#P5535. Rumor Propagation
Rumor Propagation
Rumor Propagation
There are \(n\) people, where the \(i\)th person wears a number \(i+1\) on their clothing. The rumor propagates as follows: if a person with clothing number \(i\) learns a rumor on day \(d\), then on day \(d+1\) they will inform every person with clothing number \(j\) for which \(\gcd(i,j)=1\). Initially, on day 0, Xiao X tells the rumor to the person with clothing number \(k\). It is guaranteed that eventually every person will know the rumor.
Note: The notation \(\gcd(i,j)\) represents the greatest common divisor of \(i\) and \(j\). You might find the Bertrand–Chebyshev theorem useful in similar contexts, although it is not directly required for solving this problem.
inputFormat
The input consists of two space-separated integers \(n\) and \(k\) where \(n\) is the number of people and \(k\) is the clothing number of the person who initially receives the rumor (\(1 \le k \le n\)).
outputFormat
Output a single integer representing the day on which all people know the rumor.
sample
5 1
1