def extendGcd(m,b):
if b>m:
m,b=b,m
x1,x2,x3=1,0,m
y1,y2,y3=0,1,b
while True:
if y3==0:
return None
if y3==1:
return y2%m
Q=x3//y3
t1,t2,t3=x1-Q*y1,x2-Q*y2,x3-Q*y3
x1,x2,x3=y1,y2,y3
y1,y2,y3=t1,t2,t3



