eolymp
bolt
Try our new interface for solving problems
Problems

GCD Guessing Game

GCD Guessing Game

Paul had a birthday yesterday, and they were playing a guessing game there with Andrew: Andrew was trying to guess Paul’s age. Andrew knew that Paul’s age is an integer between \textbf{1} and \textbf{n}, inclusive. Andrew can guess any number \textbf{x} between \textbf{1} and \textbf{n}, and Paul will tell him what is the greatest common divisor of \textbf{x} and his age. Here’s a possible course of the game for \textbf{n = 6}. Andrew starts with guessing \textbf{3}, and Paul replies that the greatest common divisor of \textbf{3} and his age is \textbf{1}. That means that Paul’s age can’t be \textbf{3} or \textbf{6}, but can still be \textbf{1}, \textbf{2}, \textbf{4} or \textbf{5}. Andrew continues with guessing \textbf{2}, and Paul replies \textbf{2}. That means that Paul’s age can’t be \textbf{1} or \textbf{5}, and the only two remaining choices are \textbf{2} and \textbf{4}. Finally, Andrew guesses \textbf{4}, and Paul replies \textbf{2}. That means that Paul’s age is \textbf{2}, and the game is over. Andrew needed three guesses in the above example, but it’s possible to always determine Paul’s age in at most two guesses for \textbf{n = 6}. The optimal strategy for Andrew is: at the first step, guess \textbf{6}. If Paul says \textbf{1}, then its \textbf{1} or \textbf{5} and he can check which one by guessing \textbf{5}. If Paul says \textbf{2}, then its \textbf{2} or \textbf{4}, and he can check by guesing \textbf{4} as we’ve seen above. If Paul says \textbf{3}, then we already know the answer is \textbf{3}. Finally, if Paul says \textbf{6}, the answer is \textbf{6}. What is the number of guesses required in the worst case if Andrew guesses optimally for the given \textbf{n}? \InputFile The input file contains one integer \textbf{n}, \textbf{2} ≤ \textbf{n} ≤ \textbf{10000}. \OutputFile Output one integer --- the number of guesses Andrew will need to make in the worst case.
Time limit 1 second
Memory limit 64 MiB
Input example #1
6
Output example #1
2