Halloween Kemonomimi Party 2014

Problem A: Rabbit Girls

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 ≤ N ≤ 2×109) rabbit-girls into groups of size K (1 ≤ K ≤ 2×109). However, it's possible that you can't divide the rabbit-girls evenly – in that case, you can either look for more rabbit-girls 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 Format

The first line of input will have a single integer N.
The second line of input will have a single integer K.
At least 50% of the test cases will have 1 ≤ N, K ≤ 100.

Output Format

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 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 2

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

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 256M
Added: Nov 04, 2014
Author: FatalEagle

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

What's wrong?

...Also, in case your nerdish side has a penchant for nihongo (japanese), "usagimimi" (rabbit ears) is a tad more specific than the umbrella term kemonomimi (animal ears).

It's part of a set of 4 problems (rabbitgirls, catgirls, doggirls, foxgirls).

Oh, I missed that; I'll finish a set and then go for them; thanks for your time giving us more and more problems :)

"... you can either look for more rabbit-girls ..."
This means at a rate of at most 1 per second.