Problem:


Greatest Common Divisor

Write a program which finds the greatest common divisor of two natural numbers a and b

Input

a and b are given in a line sparated by a single space.

Output

Output the greatest common divisor of a and b.

Constrants

1 ≤ a, b ≤ 109

Hint

You can use the following observation:

For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y)

Sample Input 1

54 20

Sample Output 1

2

Sample Input 2

147 105

Sample Output 2

21



Sample input:
54 20


Sample output:
2

Submission status: Memory Limit Exceeded

Solution code:
# coding:utf-8
def gcd(x,y):
    x_ans = []
    y_ans = []
    for i in range(1,x + 1):
        if x % i == 0:
            x_ans.append(i)
    for i in range(1,y + 1):
        if y % i == 0:
            y_ans.append(i)
    xset = set(x_ans)
    yset = set(y_ans)
    matched = list(xset & yset)
    print max(matched)

n = map(int, raw_input().split())
gcd(n[0],n[1])

Submission status: Memory Limit Exceeded

Solution code:
# coding:utf-8
def gcd(x,y):
    if x == y:
        print x
        return
    a = x % y
    y_ans = []
    two_ans = []
    for i in range(1,y + 1):
        if y % i == 0:
            y_ans.append(i)
    for i in range(1,a + 1):
        if a % i == 0:
            two_ans.append(i)
    yset = set(y_ans)
    twoset = set(two_ans)
    matched = list(yset & twoset)
    print max(matched) 

n = map(int, raw_input().split())
gcd(n[0],n[1])

Submission status: Memory Limit Exceeded

Solution code:
# coding:utf-8
def gcd(x,y):
    if x == y:
        print x
        return
    a = x % y
    y_ans = []
    two_ans = []
    y_ans.append(1)
    two_ans.append(1)
    for i in range(2,y / 2 + 1):
        if y % i == 0:
            y_ans.append(i)
    for i in range(2,a / 2 + 1):
        if a % i == 0:
            two_ans.append(i)
    yset = set(y_ans)
    twoset = set(two_ans)
    matched = list(yset & twoset)
    print max(matched) 

n = map(int, raw_input().split())
gcd(n[0],n[1])

Submission status: Memory Limit Exceeded

Solution code:
# coding:utf-8
def gcd(x,y):
    if x == y:
        print x
        return
    a = x % y
    y_ans = []
    two_ans = []
    y_ans.append(1)
    two_ans.append(1)
    for i in range(2,y // 2 + 1):
        if y % i == 0:
            y_ans.append(i)
    for i in range(2,a // 2 + 1):
        if a % i == 0:
            two_ans.append(i)
    yset = set(y_ans)
    twoset = set(two_ans)
    matched = list(yset & twoset)
    print max(matched) 

n = map(int, raw_input().split())
gcd(n[0],n[1])

Submission status: Memory Limit Exceeded

Solution code:
# coding:utf-8
def gcd(x,y):
    if x == y:
        print x
        return
    a = x % y
    y_ans = []
    two_ans = []
    y_ans.append(1)
    two_ans.append(1)
    for i in range(2,y // 2 + 1):
        if y % i == 0:
            y_ans.append(i)
    for i in range(2,a // 2 + 1):
        if a % i == 0:
            two_ans.append(i)
    yset = set(y_ans)
    twoset = set(two_ans)
    matched = list(yset & twoset)
    print max(matched) 

n = map(int, raw_input().split())
n.sort()
n.reverse()
gcd(n[0],n[1])

Submission status: Memory Limit Exceeded

Solution code:
# coding:utf-8
def gcd(x,y):
    if x == y:
        print x
        return
    a = x % y
    y_ans = []
    two_ans = []
    y_ans.append(1)
    two_ans.append(1)
    for i in range(2,y // 2 + 1):
        if y % i == 0:
            y_ans.append(i)
    for i in range(2,a // 2 + 1):
        if a % i == 0:
            two_ans.append(i)
    yset = set(y_ans)
    twoset = set(two_ans)
    matched = list(yset & twoset)
    print max(matched) 

n = map(int, raw_input().split())
n.sort(reverse=True)
gcd(n[0],n[1])

Submission status: Memory Limit Exceeded

Solution code:
# coding: UTF-8
def common_div(x,y):
    divisor = 0
    if x > y:
        x = x % y
        for i in range(1,x+1):
            if y % i == 0 and x % i == 0:
                divisor = i
        return divisor
    elif x == y:
        divisor = x
        return divisor
    else:
        for i in range(1,x+1):
            if y % i == 0 and x % i == 0:
                divisor = i
        return divisor

num1,num2 = raw_input().split()
maximam = common_div(int(num1), int(num2))
print(maximam)

Submission status: Memory Limit Exceeded

Solution code:
# coding: UTF-8
def common_div(x,y):
    divisor = 0
    x_mul = 0
    if x > y:
        x = x % y
        for i in range(1,x+1):
            if y % i == 0 and x % i == 0:
                divisor = i
        return divisor
    elif x == y:
        divisor = x
        return divisor
    else:
        for i in [2,3,5,7]:
            if x % i == 0:
                x_mul = i
        if x_mul != 0:
            for j in  x_mul * range(1,x+1):
                if y % j == 0 and x % j == 0:
                    divisor = j
            return divisor
        else:
            for k in range(1,x+1):
                if y % i == 0 and x % i == 0:
                    divisor = i
            return divisor


num1,num2 = raw_input().split()
maximam = common_div(int(num1), int(num2))
print(maximam)

Submission status: Memory Limit Exceeded

Solution code:
# coding: UTF-8
def common_div(x,y):
    divisor = 0
    x_mul = 0
    if x > y:
        x = x % y
        for i in range(1,x+1):
            if y % i == 0 and x % i == 0:
                divisor = i
        return divisor
    elif x == y:
        divisor = x
        return divisor
    else:
        for i in [2,3,5,7]:
            if x % i == 0:
                x_mul = i
        if x_mul != 0:
            for j in  x_mul * range(1,x+1):
                if y % j == 0 and x % j == 0:
                    divisor = j
                if x <= j:
                    break
            return divisor
        else:
            for k in range(1,x+1):
                if y % i == 0 and x % i == 0:
                    divisor = i
            return divisor


num1,num2 = raw_input().split()
maximam = common_div(int(num1), int(num2))
print(maximam)

Submission status: Accepted

Solution code:

c,d = list(map(int,input().split()))

if d>c:
    a = d
    b = c
else:
     a = c
     b = d

def gcd(x,y):
    if y == 0:
        return x
    else:
        r = x%y
        return gcd(y,r)
    
print(gcd(a,b))

Submission status: Accepted

Solution code:
twoNumbers=list(map(int,input().split()))
x=twoNumbers[0]
y=twoNumbers[1]
devidedBy=[]
syou=[]
if x>=y:
    for number in range(1, y+1):
        if y%number==0:
            if number>y//number:
                break
            else:
                if not number in devidedBy:
                    devidedBy.append(number)
                if not y//number in syou:
                    syou.append(y//number)
else:
    for number in range(1, x+1):
        if x%number==0:
            if number>x//number:
                break
            else:
                if not number in devidedBy:
                    devidedBy.append(number)
                if not x//number in syou:
                    syou.append(x//number)

if devidedBy[len(devidedBy)-1]==syou[len(syou)-1]:
    del devidedBy[len(devidedBy)-1]

devidedBy.extend(syou)
devidedBy.sort()
index=len(devidedBy)-1
while index>=0:
    if x>=y:
        if x%devidedBy[index]==0:
            print(devidedBy[index])
            break
        else:
            index-=1
    else:
        if y%devidedBy[index]==0:
            print(devidedBy[index])
            break
        else:
            index-=1

Submission status: Accepted

Solution code:
X, Y = map(int, input().split())

def gcd(_x, _y) :
    x = min(_x, _y)
    y = max(_x, _y)
    
    if x == 0 or y == 0 :
        return 0
    if x == y :
        return X
    elif y % x == 0 :
        return min(x, y)
    elif y % x != 0 :
        return gcd(y % x, x)
        
print(gcd(X, Y))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())

def gcd(a, b):
    if a == b:
        return a
    big = max(a, b)
    small = min(a, b)
    while not big % small == 0:
        big, small = small, big%small
    return small
    
print(gcd(a, b))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())

def gcd(a, b):
    big = max(a, b)
    small = min(a, b)
    while not big % small == 0:
        big, small = small, big%small
    return small
    
print(gcd(a, b))

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
while True:
    if x > y:
        x = x % y
        if x == 0:
            print(y)
            break
    else:
        y = y % x
        if y == 0:
            print(x)
            break

Submission status: Accepted

Solution code:
import math
a,b=map(int,input().split())
print(math.gcd(a,b))

Submission status: Accepted

Solution code:
def main():
    a, b = tuple(map(int,input().split()))
    if a < b:
        (a, b) = (b, a)
        # a > b となるように並べ替え
    print(gcd(a, b))

def gcd(x, y):    
    
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    a, b = tuple(map(int,input().split()))
    print(gcd(a, b))

def gcd(x, y):    
    # x > y となるように並べ替え
    if x < y:
        (x, y) = (y, x)
    return x if y == 0 else gcd(y, x%y)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
nums = sorted(list(map(int, input().split())), reverse=True)


def gcd(mx, mi):
    if mi == 0:
        return mx
    amari = mx % mi
    return gcd(mi, amari)

print(gcd(nums[0], nums[1]))

Submission status: Accepted

Solution code:
import sys

input_list = map(int, raw_input().split())

x = input_list[0]
y = input_list[1]

if x < y:
	tmp = x
	x = y
	y = tmp
elif x == y:
	print(x)
	sys.exit(0)


r = 0
while y != 0:
	r = x % y
	x = y
	y = r

print(x)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
if a > b:
    a, b = b, a
if b%a == 0:
    print(a)
else:
    while True:
        for i in range(a):
            x = i + 2
            #print(a, x)
            if a%x == 0:
                if b%x == 0:
                    c.append(x)
                    a = a//x
                    b = b//x
                    #print(c)
                    break
                elif b%(a//x) == 0:
                    c.append(a//x)
                    a = x
                    b = b//(a//x)
                    #print(c)
                    break
            #if x%1000 == 0:
                #print(x)
            if x > a**0.5:
                break
        if x > a**0.5:
            break
    s = 1
    for j in c:
        s = s * j
    print(s)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
if a > b:
    a, b = b, a
if b%a == 0:
    print(a)
else:
    while True:
        for i in range(a):
            x = i + 2
            if a%x == 0:
                if b%x == 0:
                    c.append(x)
                    a = a//x
                    b = b//x
                    break
                elif b%(a//x) == 0:
                    c.append(a//x)
                    a = x
                    b = b//(a//x)
                    break
            if x > a**0.5:
                break
        if x > a**0.5:
            break
    s = 1
    for j in c:
        s = s * j
    print(s)

Submission status: Accepted

Solution code:
def gcd(x,y):
    while y:
        x, y = y, x % y
    return x

a,b = map(int, raw_input().split())
print gcd(a, b)

Submission status: Accepted

Solution code:
def gcd(x, y):
    if y == 0:
        return print(x)
    return gcd(y, x % y)

x, y = map(int, input().split())
gcd(x, y)

Submission status: Accepted

Solution code:
def gcd(aa,bb):
    while bb!=0:
        r=bb
        bb=aa%bb
        aa=r
    return aa
a,b=map(int,raw_input().strip().split())
#print a,b
print gcd(a,b)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        a, b = b, a % b
    return a
print(gcd(*map(int, input().split())))

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
def gcd(x,y):
    q = max(x,y)  %  min(x,y)
    if q == 0 :
        return [min(x,y),0]
    return gcd(min(x,y),q)

print(max(gcd(a,b)))

Submission status: Accepted

Solution code:
def sort_two_nums_tuple(x,y):
    return max(x,y),min(x,y)

def calculate_gcd(x,y):
    remain = float('inf')
    while remain != 0:
        remain = x % y
        x = y
        y = remain
    return x

input_x,input_y = map(int,input().split())
x,y = sort_two_nums_tuple(input_x,input_y)
ans = calculate_gcd(x,y)
print(ans)

Submission status: Accepted

Solution code:
def gcd(x,y):
    a=max(x,y)
    b=min(x,y)
    if a%b==0:
        return b
    else:
        return gcd(a%b,b)
A,B=map(int,input().split())
print(gcd(A,B))

Submission status: Accepted

Solution code:
import math
def div(x, y): #x>y
    A = 1
    for i in range(1, int(math.sqrt(x))+1):
        if x % i == 0 and y % i == 0:
            A = max(A, i)
        j = int(x/i)
        if x % j == 0 and y % j == 0:
            A = max(A, j)
    return A
x, y = map(int, input().split(" "))
print(div(x,y))

Submission status: Accepted

Solution code:
def gcd(a, b):
    c = max([a, b])
    d = min([a, b])
    if c % d == 0:
        return d
    else:
        return gcd(d, c % d)
        
nums = input().split()
print(gcd(int(nums[0]), int(nums[1])))

Submission status: Accepted

Solution code:
x, y = map(int, input().split())

if x < y:
    x, y = y, x
while y > 0:
    x, y = y, x % y
print(x)

Submission status: Accepted

Solution code:
from sys import stdin
 
x, y = [int(x) for x in stdin.readline().rstrip().split()]
 
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a
 
print(gcd(x, y))

Submission status: Accepted

Solution code:
def gcd(x, y):
    while x > 0:
        x, y = y % x, x
    return y


xy = list(map(int, input().split()))
x = xy[0]
y = xy[1]
y = gcd(x, y)
print(y)

Submission status: Accepted

Solution code:
def divide(a, b):
	if a < b:
		return divide(b, a)
	if b == 0:
		return a
	return divide(b, a%b)
	
nums=list(map(int,input().split()))

ans = divide(nums[0], nums[1])

print(ans)

Submission status: Accepted

Solution code:

def gcd(a,b):
  if a<b: a,b=b,a
  c=a%b
  if c==0:
    print(b)
  else:
    return gcd(b,c)

a,b = map(int, input().split())
gcd(a,b)

Submission status: Accepted

Solution code:
import math
a,b = map(int,input().split())

print(math.gcd(a,b))

Submission status: Accepted

Solution code:
def gcd(x,y):
  x,y=max(x,y),min(x,y)
  if y==0:
    return x
  else:
    return gcd(y, x%y)

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

Submission status: Accepted

Solution code:
x,y = map(int,input().split(" "))

def gdp(x,y):
    if x > y:
        big = x
        small = y
    else:
        big = y
        small = x
    if big%small == 0:
        print(small)
        return
    else:
        gdp(small,big%small)

gdp(x,y)

Submission status: Accepted

Solution code:
x,y = map(int,input().split(" "))

while y != 0:
    x,y=y,x%y

print(x)

Submission status: Accepted

Solution code:
def gcd(x, y):
    if x < y:
        return gcd(y, x)
    if y == 0:
        return x
    return gcd(y, x % y)
x, y = map(int, input().split())
print(gcd(x, y))

Submission status: Accepted

Solution code:
gcd=list(map(int,input().split()))

if gcd[0]<gcd[1]:
	gcd[0],gcd[1]=gcd[1],gcd[0]
while gcd[1]>0:
	r=gcd[0]%gcd[1]
	gcd[0]=gcd[1]
	gcd[1]=r
print(gcd[0])

Submission status: Accepted

Solution code:
import math

def gcd(a,b):
    if a<b: a,b=b,a
    c=a%b
    if c==0:
        return b
    else:
        return gcd(b,c)
    
S=[ int(x) for x in input().split()]    
print(gcd(S[0],S[1]))

Submission status: Accepted

Solution code:
def main():
    x, y = map(int, input().split())
    if y > x:
        x, y = y, x
    while y > 0:
        r = x % y
        x = y
        y = r

    print(x)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,y = map(int,input().split())

def swap(x,y):
    temp = x
    x = y
    y = temp
    return(x,y)

def gcd(x,y):
    if x < y:
        x,y= swap(x,y)

    while(x != y and y != 0):
        x = x%y
        x,y = swap(x,y)
    print(x)

gcd(x,y)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def gcd ( ax, ay):
    x = ax
    y = ay
    while (True):
        if x < y :
            tmp = x
            x = y
            y = tmp
        x=x %y
        if x == 0:
            return y
        elif x == 1:
            return 1



x,y = map(int, input().split())
print(gcd(x,y))

Submission status: Accepted

Solution code:
x,y=map(int,input().split())

def gg(a,b):
    if a%b==0 and b%b==0:
        return b
    return gg(b,a%b)

if x>y:
    print(gg(x,y))
else:
    print(gg(y,x))

Submission status: Accepted

Solution code:
def calc_gcd(a,b):
    if a < b:
        a,b=b,a
    if b == 0:
        return a
    return calc_gcd(b,a%b)

x,y=map(int,input().split())
print("%d"%(calc_gcd(x,y)))

Submission status: Accepted

Solution code:
data = list(map(int,input().split()))
if(data[0] < data[1]): data[0],data[1] = data[1],data[0]

def gcd(x,y):
    return x if y == 0 else gcd(y,x%y)

print(gcd(data[0],data[1]))

Submission status: Accepted

Solution code:
def GCD_calc(A,B):
    if(A>=B):
        big = A
        small = B
    else:
        big = B
        small = A
    r=big%small
    if r == 0:
        return small
    else:
        return GCD_calc(small,r)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
if a > b: a, b = b, a

while True:
    if b % a == 0:
        print(a)
        break
    else:
        b = b % a
        if a > b: a, b = b, a

Submission status: Accepted

Solution code:
def gcd(a, b):
    while b != 0:
        # gcd(a, b) == gcd(b, a%b)
        rem = a % b
        a = b
        b = rem
    return a

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

Submission status: Accepted

Solution code:
x, y = (int(s) for s in input().split())
while y > 0:
    x, y = y, x % y
print(x)

Submission status: Accepted

Solution code:
def main():
    nums = map(int, raw_input().split())
    print gcd(nums[0], nums[1])

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

main()

Submission status: Accepted

Solution code:
a,b = map(int,raw_input().split(' '))
while(True):
	if(a == b):
		print a
		break
	if(a < b):
		t = a
		a = b
		b = t
	a,b = b,a%b
	if(b == 0):
		print a
		break

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
if a<b:
	a,b = b,a
while 1:
	if a%b==0:
		break
	a,b = b,a%b
print(b)

Submission status: Accepted

Solution code:
a, b = map(int, raw_input().split())

def gcd(a,b):
	c = a%b
	if c==0:
		return b
	elif c == 1:
		return c
	else:
		return gcd(b, c)

if a > b:
	print gcd(a, b)
elif a < b:
	print gcd(b, a)
else:
	print a

Submission status: Accepted

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

a, b = map(int, raw_input().split(' '))

print gcd(a, b)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())

mini, big = (a, b) if a < b else (b, a)

while True:
    rem = big % mini
    if rem == 0:
        break
    mini, big = rem, mini

print(mini)

Submission status: Accepted

Solution code:
l=[int(x) for x in raw_input().split(" ")]

def gcd(a,b):
    if a > b:
        mod = a % b
        if mod==0: return b
        return gcd(b, mod)
    else:
        mod = b % a
        if mod==0: return a
        return gcd(a, mod)

print gcd(l[0], l[1])

Submission status: Accepted

Solution code:
import sys


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
    
if __name__ == '__main__':
    ab = sys.stdin.readline()
    a, b = ab.split()
    a, b = int(a), int(b)
    
    sys.stdout.write(str(gcd(a, b)) + '\n')

Submission status: Accepted

Solution code:
def euclid(m,n):
    while m%n>0:
        m,n=n , m%n
    else:
        return n

x,y = map(int,raw_input().split())
if x < y:
    x,y = y,x
print euclid(x,y)

Submission status: Accepted

Solution code:
[x,y] = list(map(int, input().split()))

if x<y:
	temp = x
	x = y
	y = temp

while y>0:
	temp = x % y
	x = y
	y = temp

print(x)

Submission status: Accepted

Solution code:
import fractions

if __name__ == '__main__':
    x, y = [int(_) for _ in input().split()]
    print(fractions.gcd(x, y))

Submission status: Accepted

Solution code:
x, y = map(int, input().split())


def gcd(x, y):
    if x % y == 0:
        return y
    elif x % y == 1:
        return 1
    else:
        return gcd(y, x % y)

if x >= y:
    n = gcd(x, y)
    print(n)
else:
    n = gcd(y, x)
    print(n)

Submission status: Accepted

Solution code:
x,y = map(int, raw_input().split())

while y > 0:
    x,y = y,x%y

print x

Submission status: Accepted

Solution code:
#coding:utf-8
x,y = list(map(int,input().split()))
if x < y:
    x,y = y,x
r = x % y

while r != 0:
    x = y
    y = r
    r = x % y

print(y)

Submission status: Accepted

Solution code:
#coding:utf-8
x,y = map(int,input().split())
while x%y != 0:
    x,y = y,x%y

print(y)

Submission status: Accepted

Solution code:
def gcd( x, y ):
	if 1 < y < x:
		return gcd( y, x%y )
	else:
		if y == 1:
			return 1
		return x

a, b = [ int( val ) for val in raw_input( ).split( " " ) ]
if a < b:
	a, b = b, a
print( gcd( a, b ) )

Submission status: Accepted

Solution code:
def gcd( x, y ):
	if 1 < y < x:
		return gcd( y, x%y )
	else:
		if y == 1:
			return 1
		return x

a, b = [ int( val ) for val in input( ).split( " " ) ]
if a < b:
	a, b = b, a
print( gcd( a, b ) )

Submission status: Accepted

Solution code:
def gcd( x, y ):
	if 0 == y:
		return x
	else:
		return gcd( y, x%y )
		
a, b = [ int( val ) for val in input( ).split( " " ) ]
if a < b:
	a, b = b, a
print( gcd( a, b ) )

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def gcd(x, y):
    if y > x:
        x, y = y, x
    if y == 0:
        return x
    return gcd(y, x % y)

x, y = map(int, input().split())
print(gcd(x, y))

Submission status: Accepted

Solution code:
# coding: utf-8

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

def main():
    a, b = map(int, raw_input().split())
    print gcd(a, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python

def GCD(x,y):
    while y!=0:
        tmp=y
        y=x%y
        x=tmp
    return x

if __name__ == "__main__":
    x,y=list(map(int,input().split()))
    if x<y:
        tmp=x
        x=y
        y=tmp
    print(GCD(x,y))

Submission status: Accepted

Solution code:
from fractions import gcd
x, y = map(int, input().split())
print(gcd(x, y))

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
while y != 0:
    x, y = y, x % y
print(x)

Submission status: Accepted

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

print(gcd(*map(int, input().split())))

Submission status: Accepted

Solution code:
# GCD
def gcd(x, y):
    if x % y > 0:
        r = x % y
        d = gcd(y, r)
    else:
        d = y

    return d


x, y = [int(i) for i in input().split()]

if x < y:
    buff = x
    x = y
    y = buff
elif x == y:
    print(x)
    exit()

d = gcd(x, y)

print(d)

Submission status: Accepted

Solution code:
x, y = map(int, raw_input().split())
flag = True
while flag:
    if y > x:
        x, y = y, x
    mod = x % y
    x, y = y, mod
    if mod == 0:
        print x
        quit()

Submission status: Accepted

Solution code:
#coding:utf-8
#1_1_B
def gcd(x, y):
    while x%y != 0:
        x, y = y, x%y
    return y

x, y = map(int, input().split())
print(gcd(x, y))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())

if a<b:
	(a,b)=(b,a)

while b!=0:
	(a,b)=(b,a%b)

print(a)

Submission status: Accepted

Solution code:
def Euclidean(input_list):
  # print input_list
  x = input_list[1]
  y = input_list[0]
  r = x % y
  if r != 0:
    list = [r, y]
    list.sort()
    return Euclidean(list)
  else:
    return y

list = map(int, raw_input().split(" "))
list.sort()
print Euclidean(list)

Submission status: Accepted

Solution code:
num_list = raw_input().split()
num_list = map(int, num_list)

def gcd(x, y): 
    if x < y:
        x, y = y, x
    while (y>0):
        r = x % y 
        x = y 
        y = r 

    return x

x = num_list[0]
y = num_list[1]

print gcd(x, y)

Submission status: Accepted

Solution code:
s = input()
x,y = map(int,s.split())

while(x != y or x>1 or y > 1):
    if(x < y):
        tmp = x
        x = y
        y = tmp
    if( y == 0):
        break

    x %= y
print(x)

Submission status: Accepted

Solution code:
ex = raw_input()
n_s, m_s = ex.split()
n = int(n_s)
m = int(m_s)

while n > 0:
    temp = n
    n = m % n
    m = temp

print m

Submission status: Accepted

Solution code:
import sys

def div(x, y):
    if x % y == 0:
        print y
    else:
        div(y, x%y)


line = sys.stdin.readline()
x, y = line.split(" ")

x = int(x)
y = int(y)

if x < y:
    x, y = y, x

if x == y:
    print x

else:
    div(x, y)

Submission status: Accepted

Solution code:
def grecom(x,y):
    if(x==0 or y==0):
        return x+y
    if(x==1 or y==1):
        return 1
    if(x==y):
        return x
    if(y>x):
        return grecom(y%x,x)
    else:
        return grecom(x%y,y)

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

Submission status: Accepted

Solution code:
import sys

def gcd(x, y):
  if y == 1:
    return 1
  elif y == 0:
    return x
  else:
    return gcd(y, x % y)

line = sys.stdin.readline()
(a, b) = line.split()
a = int(a)
b = int(b)
if a > b:
  b, a = a, b

print gcd(a, b)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())

def gcd(a, b):
  if a > b:
    a, b = b, a

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

print(gcd(a, b))

Submission status: Accepted

Solution code:
inp = map(int, raw_input().split())
x = max(inp)
y = min(inp)
while True:
    r = x % y
    x = y
    y = r
    if y == 0:
        break
print x

Submission status: Accepted

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

def main():
	a,b=map(int,raw_input().split())
	print(gcd(a,b))

if __name__=='__main__':
	main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def mygcd(x, y):
    if x == 0 or y == 0:
        return max(x, y)
    else:
        (x1, y1) = (max(x, y), min(x, y))
        return mygcd(y, x % y)


def main():
    print(mygcd(*map(int, input().split())))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

x, y = [int(n) for n in input().split()]
print(gcd(x, y))

Submission status: Accepted

Solution code:
#--coding:utf-8

def gcd(x, y):
    if x < y:
        gcd(y,x)
    if x%y == 0:
        return y 
    else:
        return gcd(y, x%y)

x, y = map(int, raw_input().split())
print gcd(x, y)

Submission status: Accepted

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

a,b = map(int, raw_input().split(' '))
if a > b:
    print gcd(a,b)
else:
    print gcd(b,a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys                                               
for i in sys.stdin:
    lst = i.split(' ')
    lst = map(int, lst)
    lst.sort()

    n = 1
    maxn = 1
    while n*n <= lst[0]:
        if lst[0]%n == 0 and lst[1]%(lst[0]/n) == 0:
            print lst[0]/n
            break
        elif lst[0]%n == 0 and lst[1]%n == 0:
            maxn = n
        n = n+1
    else:
        print maxn
    sys.exit(0)

Submission status: Accepted

Solution code:
def gcd(a, b):
    # ?????§??¬?´???°
    while b > 0:
        a, b = b, a % b
    return a
a, b = map(int, input().split())
print(gcd(a, b))

Submission status: Accepted

Solution code:
x, y = map(int, input().split())

if x > y:
    x, y = y, x

while x:
    x, y = y % x, x

print(y)

Submission status: Accepted

Solution code:
def gcd(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp

    while y > 0:
        r = x % y
        x = y
        y = r

    return x

if __name__ == "__main__":
    x, y = map(int, input().split())
    print(gcd(x, y))

Submission status: Accepted

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

a, b = map(int, input().split())
if a < b:
    a, b = b, a
print(gcd(a, b))

Submission status: Accepted

Solution code:
x, y = [int(n) for n in input().split()]
while True:
    tmp = x % y
    if tmp == 0:
        break
    x, y = y, tmp
print(y)

Submission status: Accepted

Solution code:
def euclideanAlg(n, m):
    r = n % m
    if r == 0:
        return m
    else:
        return euclideanAlg(m, r)

if __name__ == "__main__":
    A = map(int, raw_input().split())
    print euclideanAlg(A[0], A[1])

Submission status: Accepted

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

s = map(int, raw_input().split())
if s[0] < s[1]:
    print "%d" % gcd(s[1], s[0])
else:
    print "%d" % gcd(s[1], s[0])

Submission status: Accepted

Solution code:
x,y = map(int, raw_input().split())
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)
print gcd(x,y)

Submission status: Accepted

Solution code:
a=map(int,raw_input().split())
a.sort()
while a[1]%a[0]!=0:
 a[0],a[1]=a[1]%a[0],a[0]
print(a[0])

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
if a < b:
    a, b = b, a
while a % b != 0:
    a, b = b, a % b
print(b)

Submission status: Accepted

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

n1,n2 = map(int,raw_input().split())
print gcd(n1,n2)

Submission status: Accepted

Solution code:
def gcd(a, b):
	if a < b:
		tmp = a
		a = b
		b = tmp
	
	r = a % b
	while r != 0:
		a = b
		b = r
		r = a % b

	return b

if __name__ == '__main__':
	l = list(map(int, input().split()))
	x = l[0]
	y = l[1]

	ans = gcd(x, y)
	print(ans)

Submission status: Accepted

Solution code:
A,B= map(int, raw_input().split())
while B > 0:
    A, B = B, A%B
print A

Submission status: Accepted

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

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

a, b = map(int, raw_input().split())
print gcd(a, b)

Submission status: Accepted

Solution code:
def gcd(b, s):
    mod = b % s
    if mod != 0:
        return gcd(s, mod)
        
    else:
        return s

x, y = map(int, input().split())
b = max(x, y)
s = min(x, y)
a = gcd(b, s)
print(a)

Submission status: Accepted

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

x,y=map(int,raw_input().split())
print(gcd(x,y))

Submission status: Accepted

Solution code:
x,y = map(int, input().split())
def gcd(x,y):
    return y, x%y
while y !=0: 
    x,y = gcd(x,y)
print(x)

Submission status: Accepted

Solution code:
import sys
def gcd(a, b):
    while b != a :
        if a > b:
             a -= b 
        elif b > a:
            b -= a
    return a

x,y = map(int, raw_input().split())
a = gcd(x,y)
print a