Given any integer x, Aoki can do the operation below. Operation: Replace x with the…
- User
Given any integer x, Aoki can do the operation below.
Operation: Replace x with the absolute difference of x and K.
You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
Constraints
- 0 ≤ N ≤ 10^{18}
- 1 ≤ K ≤ 10^{18}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the minimum possible value taken by N after Aoki does the operation zero or more times.
Examples
Input
7 4
Output
1
Input
2 6
Output
2
Input
1000000000000000000 1
Output
0
Assistant
pythonn, k = map(int, input().split()) if k == 0: print(n) else: r = n % k print(min(r, k - r))Wait, but wait a minute. What if k is zero? According to the problem statement, K is at least 1, so the case where k is zero isn't possible. So the code can be simplified.
The problem says 1 ≤ K ≤ 1e18, so the code can omit checking for k ==0. So the correct code is:
pythonn, k = map(int, input().split()) r = n % k print(min(r, k - r))But wait, in the case where r is zero, then k - r is k, which is larger than zero. So min(0, k) is 0. Which is correct.
Yes. For example, if n is 8 and k is 4, r is 0. Then min(0,4) is 0. Correct.
Another example, n=0 and k=5. r is 0. min(0,5) is 0. Correct.
So the code can be written as:
n, k = map(int, input().split()) r = n % k print(min(r, k - r))
But wait, when n is 0? Because 0 mod k is zero, so the code outputs min(0, k -0) which is zero. Correct.
So this code handles all cases.
So the code is correct.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.