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. a = b
  14. b = ta-(ta/b)*b
  15. if b == 0:
  16. print '('+FirstA+','+FirstB+')='+str(a)
  17. print 'x='+str(x2)+' y='+str(y2)
  18. break
  19. print a,b
  20. tx = x1 #We have to remember x1,y1 to calculate x2 and y2, if we didn't it
  21. ty = y1 #then we couldn't do it
  22. x1 = x2
  23. y1 = y2
  24. x2 = tx - x2*(a/b)
  25. y2 = ty - y2*(a/b)
  26.  
  27.  
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