Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_gcd(a, b):
- if a > b:
- c = int(a - b)
- if c == 0: print "a =",a,"and b =",b
- elif c == 1:
- print "GCD = 1"
- exit
- else: return find_gcd(c, b)
- elif b > a:
- c = int(b - a)
- if c == 0: print "a =",a,"and b =",b
- elif c == 1:
- print "GCD = 1"
- exit
- else: return find_gcd(a, c)
- else:
- print "GCD =",a
- exit
- a = int(raw_input('Value of a\n'))
- b = int(raw_input('Value of b\n'))
- find_gcd(a, b)
- """ In its simplest form, Euclid's algorithm starts with a pair of positive integers and forms a new pair that consists of the smaller number and the difference between the larger and smaller numbers.
- The process repeats until the numbers are equal.
- That number then is the greatest common divisor of the original pair.
- Note: Lowest common divisor is 1
- """
Advertisement
Add Comment
Please, Sign In to add comment