Tennis Score
Time limit2sMemory limit1024 MB
Given the final score a:b, find the minimum possible sum of gcd values over every score visited on a path from 0:0 to a:b.
- Level
Medium6 of 10
- Topics
- Number theory, Greedy
- Solved
- No attempts yet
Statement
Aurora and Notgrass decided to play tennis and asked Flitl to referee. At the start the score was . Then, several times, one of the players gained point. The game ended with the score .
Fislvit was bored, so she computed the sum of the greatest common divisors of the players' points after each change of the score. is the greatest common divisor of two numbers. For example, the game could have gone like this:
- ,
- ,
- ,
- ,
- ,
In that case Fislvit's sum would be .
After the game, Fislvit wondered what the smallest possible value of her sum could be. Help her find it.
Input
The input contains two integers and on a single line, the final points of Aurora and Notgrass ().
Output
Print one integer, the minimum value that Fislvit's sum could have had.