GCD and Shortest Path
Time limit1sMemory limit1024 MB
Count the vertices x from 1 to N whose shortest-path distance to K in the coprime graph equals gcd(x, K).
- Level
Medium7 of 10
- Topics
- Number theory, Graph, Math
- Solved
- No attempts yet
Problem
A graph with vertices, numbered from to , is given. The graph has the following property.
For two distinct integers that satisfy :
- If , an edge connects vertex and vertex .
- If , no edge connects vertex and vertex .
Define as the length of the shortest path between vertex and vertex . If no path connects the two vertices, define . By definition, .
Given an integer with , count the integers with that satisfy .
Input
Print the first line with the integer and the integer , separated by a space. ()
Output
On the first line, print the number of integers that satisfy the condition.
Hint
is the greatest common divisor of and .
The length of a path is the number of edges it contains. The length of the shortest path is the minimum of these lengths.