Hungry Lemurs
Limits: 2 sec., 256 MiB
Skipper : "Private, you have to feed all lemurs on Madagascar!".
There are K lemurs on Madagascar and Private has N bananas. He has to give away all his bananas to lemurs. Lemurs are happy if all of them get the same number of bananas (even if they don’t get any). In one minute Private can do one of the following:
Find one banana.
Discard one banana (eat).
Increase a population of lemurs on Madagascar by one.
If there are at least two lemurs remove one of them from Madagascar (don’t ask how).
Help Private and find the minimum number of minutes Private needs to satisfy all the lemurs and complete Skipper’s task.
Input
The only line of the input contains two space-separated integers N and K.
Output
Output the single integer – the minimum number of minutes.
Constraints
\(1 \le K,N \le 10^5\)
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 47 17 | 2 |
Notes
Private has to add one banana and decrease the number of lemurs by one.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|