boris-vlasenko

Водолей

Apr 16th, 2016
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def gcd(a, b):
  2.     while b:
  3.         a, b = b, a % b
  4.     return a
  5. a=int(input())
  6. b=int(input())
  7. x=int(input())
  8. seja=0
  9. sejb=0
  10. if x%gcd(a,b)!=0 or (x>a and x>b):
  11.     print("Impossible")
  12. else:
  13.    
  14.     while x!=sejb and x!=seja:
  15.         if sejb==0:
  16.             print(">B")
  17.             sejb=b
  18.         if x==sejb or x==seja:
  19.             break
  20.         if seja==a:
  21.             print("A>")
  22.             seja=0
  23.         if x==sejb or x==seja:
  24.             break        
  25.        
  26.        
  27.         print("B>A")
  28.         if seja+sejb>=a:
  29.             (seja, sejb )=(a, sejb-(a-seja))
  30.         else:
  31.             (seja, sejb)=(seja+sejb, 0)
Advertisement
Add Comment
Please, Sign In to add comment