cswork / OAOpen practice workspace

OtherOA #14

Minimum Extra Chocolates

Estimated MediumJudge-ready

Topics (AI-labelled)Bits & Math

Add a non-negative number of chocolates to each of the two boxes so that Drake's total becomes a positive integer multiple of Alex's total, and find the minimum total added. This site makes k≥1, X,Y≥0 and the ranges explicit.

Input

One line with two positive integers A and B (1≤A,B≤10^9).

Output

Output the minimum non-negative integer X+Y such that some positive integer k satisfies k(A+X)=B+Y.

Example 1

Input:

8 16

Output:

0

Example 2

Input:

7 37

Output:

4

Example 3

Input:

70 229

Output:

9

Editorial

Loading solution…