IOI Kyrgyzstan Qualification Round 2019 Question 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

IOI Kyrgyzstan Qualification Round 2019

Bishkek, April 2019

Task A. Amazing Frog


Time limit: 2 seconds
Memory limit: 256MB

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

You might also like