Halloween '14 P1 - Rabbit Girls

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

This morning, you woke up and realized that some rabbits have turned into girls! In light of this exciting event, you have decided to play with them (play card games, that is). Before you can do that, you have to put the N (1 \le N \le 2 \times 10^9) rabbit-girls into groups of size K (1 \le K \le 2 \times 10^9). However, it's possible that you can't divide the rabbit-girls evenly — in that case, you can either look for more rabbit-girls (finding them at a rate of 1 per second) or apologize to an existing one and then let her play on one of your virtually unlimited computers instead of participating in the group activity. Each of these actions will cost you 1 second to perform, and you can perform the first action an unlimited number of times and the second action as many times as there are currently rabbit-girls. Determine the minimum amount of time you need before you can divide the rabbit-girls (which may have increased or decreased) evenly into groups of size K (of which there must be at least one).

Input Specification

The first line of input will have N.

The second line of input will have K.

At least 50% of the test cases will have 1 \le N, K \le 100.

Output Specification

The first and only line of output should be the minimum number of seconds you need to split the rabbit-girls into groups of size K in accordance with the conditions listed above.

Sample Input 1

3
2

Sample Output 1

1

Explanation for Sample Output 1

You can get either 2 or 4 rabbit-girls after 1 second, which are both evenly divisible by K = 2.

Sample Input 2

10
5

Sample Output 2

0

Explanation for Sample Output 2

The number of rabbit-girls can already be evenly divided into 2 groups.


Comments


  • -1
    Nils_Emmenegger  commented on Dec. 30, 2020, 5:13 p.m.

    The group size can be greater than the rabbits, and there must be at least one group.


  • 2
    circleous  commented on March 16, 2018, 2:30 p.m.

    play card game, eh. Too bad, we should just ask them to solve this problem. xD


  • -2
    omaewamoushindeiru  commented on Jan. 8, 2015, 4:12 p.m.

    Can someone explain, why I'm getting the last test-case wrong?


    • 9
      FatalEagle  commented on Jan. 8, 2015, 4:30 p.m.

      Your algorithm is wrong.