1def EuclideanGcd(a, b):
2 if b:
3 return EuclideanGcd(b, a%b)
4 else:
5 return a
6
7def extendEuclidean(a, b, s1=1, s2=0, t1=0, t2=1):
8 if b:
9 r=a%b
10 return extendEuclidean(b, r, s2, s1-s2*(a//b), t2, t1-t2*(a//b))
11
12 return a, s1, t1
13
14def diophantine(a, b, c):
15 d=EuclideanGcd(a, b)
16 if c%d:
17 return None
18 _, x1, y1 = extendEuclidean(a//d, b//d)
19
20 return x1*c//d, f'{x1*c//d} + k{b//d}', y1*c//d, f'{y1*c//d} - k{a//d}'