Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher.

Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k$, he needs to choose the smallest one.

Given his mathematical talent, Neko had no trouble getting Wrong Answer on this problem. Can you help him solve it?


-----Input-----

The only line contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).


-----Output-----

Print the smallest non-negative integer $k$ ($k \ge 0$) such that the lowest common multiple of $a+k$ and $b+k$ is the smallest possible.

If there are many possible integers $k$ giving the same value of the least common multiple, print the smallest one.


-----Examples-----
Input
6 10

Output
2
Input
21 31

Output
9
Input
5 10

Output
0


-----Note-----

In the first test, one should choose $k = 2$, as the least common multiple of $6 + 2$ and $10 + 2$ is $24$, which is the smallest least common multiple possible.

Difficulty: interview

Starter code:

Solutions:
from math import gcd
a, b = list(map(int, input().split()))
if b < a:
    a, b = b, a
if a == b:
    print(0)
    return
c = b - a
i = 1
ans = a * b // gcd(a, b)

def get(x):
    A = (a + x - 1) // x * x
    B = A - a + b
    return A * B // gcd(A, B), A

r = 0
while i * i <= c:
    if c % i == 0:
        A, AA = get(i)
        B, BB = get(c // i)
        if A < ans:
            ans = A
            r = AA - a
        if B < ans:
            ans = B
            r = BB - a
        if A == ans:
            r = min(r, AA - a)
        if B == ans:
            r = min(r, BB - a)
    i += 1
print(r)


a, b = list(map(int,input().split()))
def gcd(x,y):
	if x == 0:
		return y
	if y == 0:
		return x
	if y > x:
		y,x = x,y
	return gcd(x%y, y)
if a > b:
	a, b = b, a
k = b - a
dzielniki = []
i = 1
while i ** 2 <= k:
	if k % i == 0:
		dzielniki.append(i)
		dzielniki.append(k // i)
	i+= 1
gcdd = a * b / gcd(a,b)
wynik = 0
#print(dzielniki)
for d in dzielniki:
	aa = a - (a % d) + d
	bb = b - (b % d) + d
	#print(aa,bb)
	if aa * bb // gcd(aa,bb) <= gcdd:
		if aa * bb // gcd(aa,bb) == gcdd:
			wynik = min(d-(a%d),wynik)
		else:
			gcdd = aa * bb // gcd(aa,bb)
			wynik = d-(a%d)
print(wynik)


from math import gcd
a, b = map(int, input().split())
if a > b:
	a, b = b, a
divs = []
i = 1
while i*i <= b-a:
	if (b-a)%i == 0:
		divs.append(i)
		if i*i != b-a:
			divs.append((b-a)//i)
	i += 1
best = (a*b//gcd(a, b), 0)
for d in divs:
	rest = a%d
	if rest == 0:
		rest = d
	ths = d - rest
	if ths < 0:
		continue
	cand = ((a+ths)*(b+ths)//gcd(a+ths, b-a), ths)
	# print(d, ths, cand)
	if cand[0] < best[0]:
		best = cand
	elif cand[0] == best[0] and cand[1] < best[1]:
		best = cand
print(best[1])

import sys
input = sys.stdin.readline

a,b=list(map(int,input().split()))

if a==b:
    print(0)
    return

if a>b:
    a,b=b,a

x=b-a

import math
xr=math.ceil(math.sqrt(x))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
def lcm(x, y):
    return (x * y) // gcd(x, y)


LIST=[]
for i in range(1,xr+1):
    if x%i==0:
        LIST.append(i)
        LIST.append(x//i)

ANS=[]

for l in LIST:
    y=math.ceil(a/l)*l-a

    ANS.append([lcm(a+y,b+y),y])

    
print(min(ANS,key=lambda x:x[0])[1])



a, b = list(map(int, input().split()))
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

(a, b) = (b, a) if a > b else (a, b)
c = b - a
if c == 0:
    print(0)
    return
pc = make_divisors(c)
ctr = a*b//(gcd(a, b))
ans = 0
for p in pc:
    ak = -(-a//p)*p
    k = ak - a
    bk = -(-b//p)*p
    lc = ak*bk//gcd(ak, bk)
    if ctr > lc:
        ctr = lc
        ans = k
print(ans)


import math
a = list(map(int, input().split()))
a.sort()
diff = a[1] - a[0]

yakusuu = []
for i in range(1, int(diff**(1/2))+1):
    if diff % i == 0:
        yakusuu.append(i)
        yakusuu.append(diff//i)

yakusuu.sort()
ans = [[a[0]*a[1], 0]]

for i in yakusuu:
    x = a[0]
    y = a[1]
    k = 0
    if x % i != 0:
        k = i - x % i

    x += k
    y += k
    anstemp = (x*y//math.gcd(x, y))
    ans.append([anstemp, k])

ans.sort()
print(ans[0][1])


a, b = list(map(int, input().split()))
if a == b: print(0)
else:
    a, b = max(a, b), min(a, b)
    x = a-b
    if a%x == 0 and b%x == 0: print(0)
    else:
        if a < 2*b: print(x - b%x)
        else:
            lis = [i for i in range(1, int(x**0.5)+1) if x%i == 0]
            for i in lis[::-1]:
                lis.append(x//i)
            import bisect
            y = bisect.bisect(lis, x//b)
            print(x//lis[y-1]-b)
# b < a
            



a, b = list(map(int, input().split()))
a, b = min(a, b), max(a, b)
if b % a == 0:
    print(0)
    return
x = b - a
dels = set()
for i in range(1, int(x ** 0.5) + 1):
    if x % i == 0:
        dels.add(i)
        dels.add(x // i)
dels = list(dels)
j = 10 ** 20
for i in dels:
    if i >= a:
        j = min(j, i - a)
print(min((x % a - a) % x, j))


from math import gcd

a, b = list(map(int, input().split()))
f = abs(a - b)
d = []
i = 1
while i * i <= f:
    if f % i == 0:
        d.append(i)
        d.append(f // i)
    i += 1

d = list(set(d))
d.sort()

def f(i):
    return (a + i) * (b + i) // gcd(a + i, b + i)

x = float('inf')
y = 0
for i in d:
    k = (i - a % i) % i
    z = f(k)
    if z < x:
        x = z
        y = k

print(y)



a, b = input().split()
a, b = int(a), int(b)
a, b = min(a, b), max(a, b)

def eu(a, b):
    if a == 0:
        return b
    if b == 0:
        return a
    if a > b:
        return eu(a%b, b)
    return eu(a, b%a)

opt = b - a
factor = []
i = 1
while i**2 < opt+1:
    if opt % i == 0:
        factor.append(i)
        factor.append(int(opt/i))
    i+=1

target = a * b / eu(a, b)
drop = 0

for i in factor:
    firstupd = a - (a % i) + i
    secondupd = b - (b % i) + i
    dres = firstupd * int(secondupd/eu(firstupd,secondupd))
    if dres <= target:
        if dres == target:
            drop = min(i-(a%i),drop)
        else:
            target = dres
            drop = i-(a%i)
print(drop)

a, b = sorted(list(map(int, input().split())))
if a == b:
    print(0)
elif a > (b-a):
    if a % (b-a) == 0:
        print(0)
    else:
        print((b-a)-(a % (b-a)))
else:
    if (b-a) % a == 0:
        print(0)
    else:
        ans = float('inf')
        for q in range(1, int((b-a)**(1/2))+2):
            if (b-a) % q == 0:
                if (b-a)//q >= a:
                    ans = min(ans, (b-a)//q)
                if q >= a:
                    ans = min(ans, q)
        print(ans-a)


def divisor(n):
    n2 = int(n ** 0.5 + 1)
    ret = set()
    for i in range(1, n2 + 1):
        if n % i == 0:
            ret.add(i)
            ret.add(n // i)
    ret = list(ret)
    ret.sort()
    return ret

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd(a, b) * b

def solve():
    inf = 1 << 60
    a, b = list(map(int,input().split()))
    if a > b:
        a, b = b, a
    if a == b:
        return 0
    ma = min(a, b)
    D = divisor(b - a)
    best_lcm = inf
    best_k = 0
    for d in D:
        r1 = a % d
        r2 = b % d
        if r1 == r2:
            k = 0
            if r1 != 0:
                k = d - r1
            lcm1 = lcm(a + k, b + k)
            if best_lcm > lcm1:
                best_lcm = lcm1
                best_k = k
            elif best_lcm == lcm1:
                best_k = min(best_k, k)
    return best_k

print(solve())



# //DEEPANSHU SAXENA(saxenad765)
# #include <bits/stdc++.h>
# #define ll long long
# #define array(x,n) (x,x+n)
# #define vector(v) (v.begin(),v.end())
# #define DEBUG(x) cout << '>' << #x << ':' << x << endl;
# #define VECTOR(v) cout << '>' << #v << ':' ; vector_out(v);
# #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
# #define ip(x) cin>>x
# #define op(x) cout<<x<<endl
# #define ops(x) cout<<x<<" "
# #define odd(x) (x&1)
# #define even(x) (!x&1)
# #define fbei(i,x,y,z) for(ll i=x;i<=y;i+=z)
# #define fbe(i,x,y) for(ll i=x;i<=y;i++)
# #define f(i,n) for(ll i=0;i<n;i++)
# #define pb push_back
# #define mp(x,y) make_pair(x,y)
# #define GCD(x,y) __gcd(x,y)
# using namespace std;
# //using codechef ide;
# //Deepanshu Saxena
# inline void filehandling()
# {
# 	#ifndef ONLINE_JUDGE
# 	freopen("input.txt", "r", stdin);
# 	freopen("output.txt", "w", stdout);
# 	#endif
# }
# vector<ll> vector_in(ll n)
# {
# 	vector<ll> v(n);
# 	for(ll i=0;i<n;i++)
# 	cin>>v[i];
# 	return v;
# }
# void vector_out(vector<ll> v)
# {
# 	for(ll i=0;i<v.size();i++)
# 	cout<<v[i]<<" ";
# 	cout<<endl;
# }
# ll vector_sum(vector<ll> v)
# {
# 	ll sum;
# 	for(ll i=0;i<v.size();i++)
# 	sum+=v[i];
# 	return sum;
# }
# int main()
# {
# 	fast
# 	filehandling();
a, b = list(map(int,input().split()))
def gcd(arg1,arg2):
	if arg1 == 0:
		return arg2
	if arg2 == 0:
		return arg1
	if arg2 > arg1:
		arg2,arg1 = arg1,arg2
	return gcd(arg1%arg2, arg2)
if a > b:
	a, b = b, a
k = b - a
array = []
i = 1
while i ** 2 <= k:
	if k % i == 0:
		array.append(i)
		array.append(k // i)
	i+= 1
gcdis = a * b / gcd(a,b)
z = 0
for d in array:
	z1 = a - (a % d) + d
	z2 = b - (b % d) + d
	if z1 * z2 // gcd(z1,z2) <= gcdis:
		if z1 * z2 // gcd(z1,z2) == gcdis:
			z = min(d-(a%d),z)
		else:
			gcdis = z1 * z2 // gcd(z1,z2)
			z = d-(a%d)
print(z)
# }



a, b = list(map(int, input().split()))
a, b = min(a, b), max(a, b)
gap = b - a
arr = []
i = 1
while i * i < gap:
    if gap % i == 0:
        arr.append(i)
        arr.append(gap // i)
    i += 1
if i * i == gap:
    arr.append(i)
arr.sort()
answer = 0
value = 10 ** 20
for i in arr:
    plus = 0
    if a % i:
        plus = i - (a % i)
    ta, tb = a + plus, b + plus
    mod = ta % tb
    while mod:
        ta = tb
        tb = mod
        mod = ta % tb
    temp = ((a + plus) * (b + plus)) // tb
    if temp < value:
        value = temp
        answer = plus
    if temp == value:
        answer = min(answer, plus)
print(answer)







are, bre = list(map(int,input().split()))







def plottt(xre,yre):
	
	
	
	
	
	
	
	
	if (xre == 0):
		
		
		
		
		
		return yre
	
	
	
	
	
	
	
	
	
	
	
	if (yre == 0):
		
		
		
		
		
		
		
		return xre





	
	
	
	
	
	
	
	
	
	
	
	if (yre > xre):
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		yre,xre = xre,yre
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return plottt(xre%yre, yre)

























if (are > bre):
	
	
	
	
	
	
	
	
	
	
	
	
	
	are, bre = bre, are
























kre = bre - are

























plkiyer = []
















ire = 1







while( ire**2<=kre):
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	if( kre % ire == 0):
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		plkiyer.append(ire)
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		plkiyer.append(kre // ire)
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	ire+= 1





























plotttd = are*bre / plottt(are,bre)





























result = 0



















for dre in plkiyer:
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	aare = are - (are % dre) + dre
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	bbre = bre - (bre % dre) + dre
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	if (aare*bbre // plottt(aare,bbre) <= plotttd):
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		if( aare*bbre // plottt(aare,bbre) == plotttd):
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			result = min(dre-(are%dre),result)
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		else:
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			plotttd = aare*bbre // plottt(aare,bbre)
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			result = dre - (are%dre)







print(result)

from math import *
def lcm(a, b):
    return a * b // gcd(a, b)
a, b = list(map(int, input().split()))

a, b = min(a, b), max(a, b)

diff = b - a





if(b % a == 0):
    print(0)

else:
    divs = set()
    for i in range(1, int(diff ** (1/2)) + 1):
        if diff % i == 0:
            divs.add(i)
            divs.add(diff // i)
    curLCM = None
    curK = None
    for can in divs:
        if b % can == 0:
            tLCM = lcm(b, a)
            tk = 0
        else:
            x = b // can
            x = (x + 1) * can
            tk = x - b
            tLCM = lcm(b + tk, a + tk)

        if curK == None:
            curK, curLCM = tk, tLCM
        else:
            if curLCM > tLCM:
                curK, curLCM = tk, tLCM
            elif curLCM == tLCM:
                curK = min(tk, curK)
    
    print(curK)
            
        
        


import math
def divisors(n):
    div = []
    d = 1
    while(d**2<=n):
        if(not n%d):
            div.append(d)
            if(d**2!=n):
                div.append(n//d)
        d+=1
    return div

def lcm(x, y):
   """This function takes two
   integers and returns the L.C.M."""
   lcm = (x*y)//math.gcd(x,y)
   return lcm

def C():
    a , b = list(map(int , input().split()))
    a , b = min(a,b) , max(a,b)
    if(not b%a):
        print(0)
        return
    divs = divisors(b-a)
    M = b*a
    k = 0
    for d in divs:
        aux_k = d*math.ceil(b/d)-b
        if(lcm(a+aux_k,b+aux_k)<M):
            M = lcm(a+aux_k,b+aux_k)
            k = aux_k
    print(k)


C()


from math import gcd
lcm = lambda x, y: (x * y) // gcd(x, y)
a, b = map(int, input().split())
c = abs(a - b)
f = 1
res = [lcm(a, b), 0]
while f * f <= c:
    if c % f == 0: 
        k = min((-a) % f, (-b) % f)
        ans = lcm(a + k, b + k)
        if res[0] > ans: res = [ans, k]
        elif res[0] == ans: res[1] = min(res[1], k)
        
        k = min((-a) % (c // f), (-b) % (c // f))    
        ans = lcm(a + k, b + k)
        if res[0] > ans: res = [ans, k]
        elif res[0] == ans: res[1] = min(res[1], k)
    f += 1
print(res[1])

import math as m

a, b = map(int, input().split())
if a > b:
	a, b = b, a
x = b - a
ans = int(5e18)
output = 0

G = 1
while G*G <= x:
	if x % G == 0:
		g = G
		k = (g - (a%g))%g
		res = (a + k) * (b + k) // m.gcd(a + k, b + k)
		if(res < ans):
			ans = res
			output = k
		elif res == ans:
			output = min(output, k)
		g = x // G
		k = (g - (a%g))%g
		res = (a + k) * (b + k) // m.gcd(a + k, b + k)
		if(res < ans):
			ans = res
			output = k
		elif res == ans:
			output = min(output, k)
	G += 1

print(output)

def mp():
    return map(int, input().split())

def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)

def lcm(a, b):
    return a * b // gcd(a, b)

a, b = mp()
a, b = min(a, b), max(a, b)

x = []
w = b - a
dl = 1
while dl ** 2 <= w:
    if w % dl == 0:
        x.append(dl)
        x.append(w // dl)
    dl += 1

kk = 0
m = 10 ** 20
for d in x:
    r = (a + d - 1) // d
    k = r * d - a    
    if lcm(a + k, b + k) < m:
        m = lcm(a + k, b + k)
        kk = k
print(kk)

a,b=tuple(map(int,input().strip().split()))
if(a==b):
    print(0)
else:
    if(a>b):
        c=a-b
    else:
        c=b-a
    import math
    i=math.ceil(math.sqrt(c))
    l=[]
    for k in range(1,i):
        if(c%k==0):
            l.append(k)
            l.append((c//k))
    if(i>0):
      if(c%i==0):
        l.append(i)

    mina=10000000000000000000000
    for mj in l:
       tt=(-a)%mj
       x=(a+tt)*(b+tt)//mj
       if(x<mina):
           mina=x
           tut=tt
    print(tut)

from math import ceil


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


a, b = [int(item) for item in input().split()]

mn = float("inf")
ans = -1
d = abs(b - a)
if d == 0:
    print(0)
else:
    for g in range(1, int(d ** .5) + 1):
        if d % g != 0:
            continue
        k = min(ceil(b / g) * g - b, ceil(a / g) * g - a)
        if (a + k) % g == 0 and (b + k) % g == 0:
            if (a + k) * (b + k) // g < mn:
                mn = (a + k) * (b + k) // g
                ans = k

        g = d // g
        k = min(ceil(b / g) * g - b, ceil(a / g) * g - a)
        if (a + k) % g == 0 and (b + k) % g == 0:
            if (a + k) * (b + k) // g < mn:
                mn = (a + k) * (b + k) // g
                ans = k

    print(ans)


A, B = map(int, input().split())
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
def lcm(a, b):
    return a*b//gcd(a,b)
def primeFactor(N):
    i = 2
    ret = {}
    n = N
    if n < 0:
        ret[-1] = 1
        n = -n
    if n == 0:
        ret[0] = 1
    d = 2
    sq = int(n ** (1/2))
    while i <= sq:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
            ret[i] = k
        if k > 0:
            sq = int(n**(1/2))
        if i == 2:
            i = 3
        elif i == 3:
            i = 5
        elif d == 2:
            i += 2
            d = 4
        else:
            i += 4
            d = 2
        
    if n > 1:
        ret[n] = 1
    return ret

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return sorted(ret)

if A == B:
    print(0)
else:
    mi = 10**100
    ans = -1
    D = divisors(abs(B-A))
    for d in D:
        k = -A%d
        L = lcm(A+k, B+k)
        if mi > L or (mi == L and ans > k):
            mi = L
            ans = k
    print(ans)

from math import sqrt,ceil
from collections import defaultdict

lim = 10**5

def sieve(N):
    """Dumb sieve of Eratosthemes, O(N*log(log(N)))"""
    b = [True]*(N+1)
    b[0] = False
    b[1] = False

    lim = ceil(sqrt(N))
    i = 2
    while i <= lim:
        if b[i]:
            for n in range(i**2,N+1,i):
                b[n] = False
        i+=1
    
    return [i for i,b in enumerate(b) if b]

P = sieve(lim)

def factor(n):
    """Given prime list, factorize n. Format as dict of factors with counts."""
    if n in P: return {n:1}

    F = []
    for p in P:
        while n%p == 0:
            n//=p
            F.append(p)
        if n in P:
            F.append(n)
            break
    else:
        if n != 1:
            F.append(n)

    C = {}
    for f in F:
        if f not in C:
            C[f] = 0
        C[f] += 1

    return C

def divisors(n):
    """Generate divisors."""
    return divisors_from_factors(factor(n))

def divisors_from_factors(F):
    """Given factors, generate divisors."""
    D = {1}
    for f in F:
        D |= {f**p*d for d in D for p in range(1,F[f]+1)}
    return D

###

from math import gcd

A,B = list(map(int,input().split()))

A,B = sorted((A,B))

def lcm(a,b):
    return a*b // gcd(a,b)

#mn = 10**100
#for k in range(0,1000000):
#    a = A+k
#    b = B+k
#    l = lcm(a,b)
#    
#    if l < mn:
#        mn = l
#        best = k
#print(best,mn)

if A == B:
    print(0)
else:
    mn = 10**100
    D = divisors(B-A)
    for t in sorted(D):
        # A+X%T == 0
        x = -A%t
        l = lcm(A+x,B+x)
        if l < mn:
            mn = l
            best = x

    print(best)



#A,B = sorted((A,B))
#d = B-A
#if A%d == 0:
#    print(0)
#else:
#    r = (A//d+1)*d - A
#    a = A+r
#    b = B+r
#    print(r, a*b // gcd(a,b))




a,b=list(map(int,input().split()))
(a,b)=min(a,b),max(a,b)
if b<2*a:
    if a==b:
        print(0)
        return
    print((-a)%(b-a))
    return
s=[1]
q=b-a
for i in range(2,int((b-a)**(1/2)+2)):
    while q%i==0:
        t=[j*i for j in s]
        for aa in t:
            s.append(aa)
        s=list(set(s))
        q=q//i
if q!=1:
    t=[j*q for j in s]
    for aa in t:
        s.append(aa)
    s=list(set(s))
s.sort()
for i in s:
    if i>=a:
        print(i-a)
        return