#GL0000334. Đếm đường đi ngắn nhất trên đồ thị các ước (Divisor Paths)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm đường đi ngắn nhất trên đồ thị các ước (Divisor Paths)
Divisor Paths
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive integer , construct an undirected graph whose vertices are all positive divisors of .
Two vertices are joined by an edge when and is prime. The edge weight equals the number of positive divisors of that are not divisors of . A path's length is the sum of edge weights; the empty path from a vertex to itself has length zero.
For each of queries, two vertices (both divisors of ) are given. Count the shortest paths from to . Paths with different edge sequences are distinct. Print each answer modulo .
Input
The first line is , the second is , and each of the next lines contains , both guaranteed divisors of .
Output
Print lines, one shortest-path count per query modulo .
Subtasks
- Subtask 1 (20 points): , , .
- Subtask 2 (30 points): , , .
- Subtask 3 (50 points): , , .
Examples
Example 1
Input
12
3
4 4
12 1
3 4
Output
1
3
1
Explanation
For a query from vertex to itself, the unique shortest path is the empty path, of weight . From to , the three shortest vertex sequences are ; ; and . From to , the only shortest sequence is .
Example 2
Input
1
1
1 1
Output
1
Explanation
When , the graph has one vertex, with one empty path to itself.
Example 3
Input
288807105787200
4
46 482955026400
12556830686400 897
414 12556830686400
4443186242880 325
Output
547558588
277147129
457421435
702277623
Explanation
The large queries require modular combinatorial counting; direct path enumeration is infeasible.
Note: Each input file contains one case using the specified format.