Problem:


Problem A: Greatest Common Divisor

Please find the greatest common divisor of two natural numbers. A clue is: The Euclid's algorithm is a way to resolve this task.

Input

The input file consists of several lines with pairs of two natural numbers in each line. The numbers do not exceed 100000.

The number of pairs (datasets) is less than 50.

Output

Your program has to print the greatest common divisor for each pair of input numbers. Print each result on a new line.

Sample Input

57 38
60 84

Output for the Sample Input

19
12



Sample input:
57 38
60 84


Sample output:
19
12

Submission status: Wrong Answer

Solution code:
ans = []
while True:
    try:
        temp = raw_input()
    except EOFError:
        break
    a,b = map(int,temp.split())
    ans.append(a+b)
for i in ans:
    print i

Submission status: Accepted

Solution code:
def gcd(m,n):  
    while m%n>0:
        m,n=n,m%n
    else:
        return n
        
while True:
    try:
        m,n = map(int,raw_input().split())
        print gcd(m,n)
    except EOFError:
        break

Submission status: Accepted

Solution code:
from fractions import gcd
while 1:
    try:
        a, b = map(int, raw_input().split())
        print gcd(a, b)
    except:
        break

Submission status: Accepted

Solution code:
def greatestCommonDivisor(num1, num2):
	if num1 % num2 == 0 : return num2
	return num1 % num2

while True:
	try:
		a,b = map(int,raw_input().split())
	except EOFError:
		break
	
	while a != b:
		if a > b:
			a = greatestCommonDivisor(a, b)
		elif b > a:
			b = greatestCommonDivisor(b, a)
			
	print a

Submission status: Accepted

Solution code:
while True:
    try:
        a, b= map(int, input().split())
        while b!= 0:
            a, b= b, a%b
        print(a)
    except:
        break

Submission status: Accepted

Solution code:
while 1:
    try:a,b=map(int,input().split())
    except:break
    while b:a,b=b,a%b
    print(a)

Submission status: Accepted

Solution code:
import fileinput

for a, b in (map(int, line.split()) for line in fileinput.input()):
    if a > b:
        a, b = b, a
    while a:
        a, b = b % a, a
    print(b)

Submission status: Accepted

Solution code:
def gcd(x, y):
    if y==0: return x
    z = x % y
    return gcd(y, z)
        
while True:
    try:
        a, b = (int(i) for i in input().split())
    except EOFError:
        break
    if a<b: print(gcd(b,a))
    else: print(gcd(a,b))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""


"""
import sys
from sys import stdin
import fractions
input = stdin.readline


def main(args):
    for line in stdin:
        n, m = map(int, line.split())
        print(fractions.gcd(n, m))



if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
from math import gcd
from sys import stdin

for line in stdin:
    a,b = [int(i) for i in line.split()]
    print(gcd(a,b))

Submission status: Accepted

Solution code:
import sys

def gcd(a,b):
    if(b):
        return gcd(b,(a%b))
    else:
        return a

List = []
for i in sys.stdin:
    List.append(i)

for data in List:
    print(gcd(int(data.split()[0]),int(data.split()[1])))

Submission status: Accepted

Solution code:
import math

def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
for l in range(len(N)):
    a,b = [int(i) for i in N[l].split()]
    print(math.gcd(a, b))

Submission status: Accepted

Solution code:
import sys
for e in sys.stdin:
    p, q = map(int, e.split())
    if p < q:p, q = q, p
    while True:
        if p % q == 0:
            print(q)
            break
        else:
            p, q = q, p % q

Submission status: Accepted

Solution code:
# AOJ 1009: Greatest Common Divisor
# Python3 2018.7.4 bal4u

def gcd(a, b):
	while b != 0:
		r = a % b
		a, b = b, r
	return a

while True:
	try: a, b = map(int, input().split())
	except: break
	print(gcd(a, b))

Submission status: Accepted

Solution code:
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b ,a%b)

def lcm(a,b):
  return a*b / gcd(a,b)

while True:
  try:
    a = map(int,raw_input().split())
    a,b = a[0],a[1]
    print gcd(a,b)
  except EOFError:
    break

Submission status: Accepted

Solution code:
import fractions                                                                 
while True:
    try:
        a,b=map(int,raw_input().split())
    except EOFError:
	break
    print fractions.gcd(a,b)

Submission status: Accepted

Solution code:
import sys
for s in sys.stdin.readlines():
    m,n = map(int, s.split())
    if n>m: n,m=m,n
    while 1:
        r = m%n
        if r==0: break
        m,n = n,r
    print n

Submission status: Accepted

Solution code:

while True:
  try:
    a, b = sorted(map(int, raw_input().split()))
    while a:
      tmp = a
      a = b % a;
      b = tmp
    print b
  except EOFError:
    break

Submission status: Accepted

Solution code:
def gmd(x, y):
    if y == 0:
        return x
    else:
        return gmd(y, x%y)
        
while True:
    try:
        a, b = map(int, raw_input().split())
        print gmd(a,b)
    except:
        break

Submission status: Accepted

Solution code:
def main():

    while True:
        try:

            a, b = map(int, input().split())
            print(euclid_algorithm(a, b))

        except EOFError as e:
            break

def euclid_algorithm(a, b):

    while a and b:

        if a > b:
            a = a - b
        else:
            b = b - a

    return a if a else b

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
while 1:
    try:
        a,b = map(int,input().split())
        print(math.gcd(a,b))
    except:
        break

Submission status: Accepted

Solution code:
import math
try:
    while True:
        a,b = input().split(" ")
        print(math.gcd(int(a),int(b)))
except EOFError:
    m = 0

Submission status: Accepted

Solution code:
import math
while True:
    try:print(math.gcd(*map(int,input().split(" "))))
    except:break

Submission status: Runtime Error

Solution code:
from math import gcd
while True:
    try:
        a, b= map(int, input().split())
        print(gcd(a, b))
    except:
        break