GCD Using While
Python
Medium
3 views
Problem Description
Read two integers a and b. Compute gcd(a,b) using Euclid while loop and output it.
Input Format
One line: a b.
Output Format
One integer gcd.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
a=int(p[0]); b=int(p[1])
a=abs(a); b=abs(b)
while b!=0:
a,b=b,a%b
sys.stdout.write(str(a))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!