Professional Documents
Culture Documents
IOI Kyrgyzstan Qualification Round 2019 Question 1
IOI Kyrgyzstan Qualification Round 2019 Question 1
IOI Kyrgyzstan Qualification Round 2019 Question 1
Frog sits on the number line at 1 and wants to reach N . At each step Frog can jump from its current
i-position to (i + k)-position if i mod k = 0 and k ≥ 1. Additionally, Frog can jump backwards by the
given number T : from i-position to (i − T )-position if i − T ≥ 1. Multiple backwards jumps are allowed.
Given integers N (2 ≤ N ≤ 2019) and T (0 ≤ T ≤ 2019), write a program that outputs the minimum
number of steps required to reach N .
Input
The first line of the input contains two integers N and T .
Output
The program should output one integer: the minimum number of steps.
Grading
Solutions that work correctly for N < 100 and T = 0 will receive 10 points.
Examples
Input Output
5 0 3
31 1 6
62 1 7
Note
In the last example Frog jumps 7 times: 1 → 2 → 4 → 8 → 16 → 32 → 31 → 62.
Page 1 of 1