fork download
  1. print 'We will find a (a,b) and x,y which a*x + b*y = (a,b)'
  2. a = int(raw_input('Enter a integer number a: '))
  3. b = int(raw_input('Enter a integer number b: '))
  4. FirstA = str(a) # We have to remember first values of a and b
  5. FirstB = str(b)
  6. x1 = 1 # Start for algorithm
  7. y1 = 0
  8. x2 = 0
  9. y2 = 1
  10.  
  11. while True:
  12. ta = a
  13. tb = b
  14. a = b
  15. b = ta-(ta/b)*b
  16. if b == 0:
  17. print '('+FirstA+','+FirstB+')='+str(a)
  18. print 'x='+str(x2)+' y='+str(y2)
  19. break
  20.  
  21. tx = x1 #We have to remember x1,y1 to calculate x2 and y2, if we didn't it
  22. ty = y1 #then we couldn't do it
  23. x1 = x2
  24. y1 = y2
  25. x2 = tx - x2*(ta/tb)
  26. y2 = ty - y2*(ta/tb)
  27.  
  28.  
Runtime error #stdin #stdout #stderr 0.01s 7696KB
stdin
Standard input is empty
stdout
We will find a (a,b) and x,y which a*x + b*y = (a,b)
Enter a integer number a: 
stderr
Traceback (most recent call last):
  File "prog.py", line 2, in <module>
EOFError: EOF when reading a line