Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # uses python3
- import sys
- def gcd_naive(n, p):
- current_gcd = 1
- for d in range(2, min(n, p) + 1):
- if n % d == 0 and p % d == 0:
- if d > current_gcd:
- current_gcd = d
- return current_gcd
- def gcd_euclid(n, p):
- gcd = 1
- # if n < 0 or p < 0:
- # gcd = 0
- # elif n + p == 0:
- # gcd = 0
- # From Chromium's style guide: Don't use else after return
- if p == 0:
- gcd = n
- return print(gcd)
- gcd_euclid(p, n % p)
- # one liner cleaner?
- def gcd_one_liner(n, p):
- gcd = n if p == 0 else gcd_one_liner(p, n % p)
- return gcd
- if __name__ == "__main__":
- user_input = sys.stdin.read()
- a, b = map(int, user_input.split())
- # gcd_euclid(a, b)
- print(gcd_one_liner(a, b))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement