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: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    a, b = sc.intarr()
    print(gcd(a, b))


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


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X, Y = map(int, input().split())
x = max(X, Y)
y = min(X, Y)
#計算量問題あり
'''
for i in range(y):
    if(x%(y-i)==0)and(y%(y-i)==0):
        print(y-i)
        exit()
'''
while x != y:
    if x > y:
        x -= y
    else:
        y -= x
print(x)

Submission status: Accepted

Solution code:
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_1_B
from fractions import gcd


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

Submission status: Accepted

Solution code:
def main():
    x, y = list(map(int, input().split()))
    if x < y:
        x, y = y, x
    n = gcd(x, y)
    print(n)

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

main()

Submission status: Accepted

Solution code:
def greatest_common_divisor(a, b):
    # a 割る b = c あまり d
    # b 割る d = ...
    residue = a % b
    if residue != 0:
        return greatest_common_divisor(b, residue)
    return b


def main():
    a, b = map(int, input().split(" "))
    print(greatest_common_divisor(a, b))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def greatest_common_devisor(x, y):
    if y == 0:
        return x
    x, y = y, x % y
    return greatest_common_devisor(x, y)
x, y = map(int, input().split(' '))
if x < y:
    tmp = x
    x = y
    y = tmp
print(greatest_common_devisor(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:
xy = list(map(int, input().split()))

x = xy[0]
y = xy[1]

while y!= 0:
    xx = y
    yy = x%y

    x = xx
    y = yy


print(x)

Submission status: Accepted

Solution code:
inputNum = input().split()

x = int(inputNum[0])
y = int(inputNum[1])

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

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

    else:
        return y

print(str(gcd(x, y)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(x,y):
	a = max(x,y)
	b = min(x,y)

	while a%b!=0:
		r = a%b
		a=b
		b=r
	return b

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

if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

print(find_gcd(x, y))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# a / b = Q + r
# r = 0
def GCD(a,b):
    r = a % b
    if(r == 0):
        return b
    else:
        return GCD(b,r)
        
a,b = map(int,input().split())

ans = GCD(a,b)
print(ans)

Submission status: Accepted

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

x = max(l)

y = min(l)
z = x%y

if z == 0:
  z = x

else:
  while x%y > 0:
    z = x%y
    if y > z :
      x = y
      y = z
    else:
      x = z

print(z)

Submission status: Accepted

Solution code:
def Euklides(m, n):
    while m % n != 0:
            tempVal = n
            n = m % n
            m = tempVal
            Euklides(m, n)
    return n

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

Submission status: Accepted

Solution code:
import math

def gcd(x, y):
    if x < y:
        x, y = y, x
    
    while y != 0:
        x, y = y, x % y
    return x
    
    '''
    if y == 0:
        return x
    
    return gcd(y, x % y)
    '''

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)


def main():
    x,y = list(map(int, input().split()))
    print(gcd(x,y))

main()

Submission status: Accepted

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

if x < y:
    x, y = y, x
    
while y > 0:
    r = x % y
    x = y
    y = r

print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

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

print(gcd(x, y))

Submission status: Accepted

Solution code:


def Euklides(m, n):
    while m % n != 0:
            tempVal = n
            n = m % n
            m = tempVal
            Euklides(m, n)
    return n
    
n, m = list(map(int, input().split()))
if m > n:
    print(Euklides(m, n))
else:
    print(Euklides(n, m))

Submission status: Accepted

Solution code:
x,y=(int(x) for x in input().split())
import math
print(math.gcd(x,y))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,y=list(map(int,input().split()))
def gcd(x,y):
    if x==1 or y==1:
        return 1
    elif x == 0:
        return y
    elif y == 0:
        return x
    elif x >=y:
        return gcd(x%y,y)
    else:
        return gcd(y%x,x)
print(gcd(x,y))

Submission status: Accepted

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

Submission status: Accepted

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

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

a = -1
while a != 0:
    a = x % y
    x = y
    y = a
    
print(x)

Submission status: Accepted

Solution code:
def greatestc(a, b):
    if a < b:
        a, b = b, a

    c = a % b    
    while c != 0:
        a = b
        b = c
        c = a % b
    return b

if __name__ == '__main__':
    a, b = input().split(' ')

    print(greatestc(int(a), int(b)))

Submission status: Accepted

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

Submission status: Accepted

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

while True:
    if x[1] % x[0] == 0:
        print(x[0])
        break
    else:
        tmp = x[1] % x[0]
        x[1] = x[0]
        x[0] = tmp

Submission status: Accepted

Solution code:
def gcd( x, y):
    if x>y:
        return gcd( x-y, y)
    elif x<y:
        return gcd( x, y-x)
    else:
        return x

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

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys

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

a, b = list(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 y>0:
    if x < y:
        x,y = y,x
    r = x%y
    x = y
    y = r
        
print(x)

Submission status: Accepted

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

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

def gcd(a, b):
    dividend = max(a, b)
    divider = min(a, b)

    if divider == 0:
        return dividend

    while dividend % divider != 0:
        r = dividend % divider
        dividend = divider
        divider = r
	#dividend, divider = divider, dividend % divider
    return divider

#dividend, divider = max(a, b), min(a, b)
#r = dividend % divider
#divider = min(a, b)

# while dividend % divider != 0:
#     r = dividend % divider
#     dividend = divider
#     divider = r
#print(r)

#print(gcdOld(20, 0))
print(gcd(a, b))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

X,Y=map(int,input().split())

def gcd(x,y):
    if x<y:
        tmp=x
        x=y
        y=tmp
    if x%y==0:
        return y
    return gcd(y,x%y)
print(gcd(X,Y))

Submission status: Accepted

Solution code:

a,b=input().split()

if a>b:
    a=int(a)
    b=int(b)

else:
    x=int(a)
    a=int(b)
    b=x

while True:
    ext=a%b
    if ext==0:
        gcd=b
        break
    else:
        a=b
        b=ext

print(gcd)

Submission status: Accepted

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

while b>0:
    b=x%y
    if b==0:
        print(y)
        break
    x=y
    y=b

Submission status: Accepted

Solution code:

def yuc(a,b):
    if a>b:
        if a%b==0:
            return b
        else:
            c=a%b
            i=yuc(b,c)
            return i
    else:
        if b%a==0:
            return a
        else:
            c=b%a
            i=yuc(a,c)
            return i
x,y=(int(i) for i in input().split())
f=yuc(x,y)
print(f)

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

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

Submission status: Accepted

Solution code:
x,y=map(int,input().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 Euclid(m,n):
    if n == 0:
        return m
    else:
        return Euclid(n, m%n)

m, n = map(int, input().split())
print(Euclid(m, n))

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())
print(gcd(a,b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def gcd(x, y):
    if x > y:
        d = x % y
        while d != 0:
            x = y 
            y = d
            d = x % y
        return y
    else:
        d = y % x
        while d != 0:
            y = x 
            x = d
            d = y % x
        return x


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
17D8101031C 杉山　祥吾 ID:keisei334 python
"""

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

x=list(map(int,input().split()))

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

"""実行結果
147 105
21
"""

Submission status: Accepted

Solution code:
a,b=(int(x) for x in input().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def gcd(x,y):
 if x > y:
   r = x % y
   while  r != 0:
    x = y
    y = r
    r = x % y
   return y
 else:
   r = y % x
   while  r != 0:
    y = x
    x = r
    r = y % x
   return x

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

print(gcd(x,y))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(a,b):
    if(b>a):
        a,b=b,a
    while(b>0):
        a,b=b,a%b
    print(a)
        
x,y=list(map(int,input().split()))
gcd(x,y)

Submission status: Accepted

Solution code:
import math

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

#print(math.gcd(x,y))

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

print(x)

Submission status: Accepted

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

    return x


x,y=map(int,input().split())
print(gcd(x,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

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:
    r = a % b
    a = b
    b = r

print(a)

Submission status: Accepted

Solution code:
from math import gcd
x, y = (int(i) for i in input().split())
print(gcd(x,y))

Submission status: Accepted

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

    return x

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

Submission status: Accepted

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

while r!=0:
    r=a%b
    a=b
    b=r
    

print(a)

Submission status: Accepted

Solution code:
from functools import reduce
import operator
def factor(a):
    b = 1
    d = []
    while b:
        if a == 2:
            d.append(a)
            break
        for i in range(2, a):
            if a % i == 0:
                b = a // i
                d.append(i)
                a = b
                break
            elif a == i+1:
                d.append(a)
                b = 0
    return d

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

x_f = factor(x)
y_f = factor(y)

common = list(set(x_f) & set(y_f))
common_n = [min(x_f.count(common[i]),y_f.count(common[i])) for i in range(len(common))]


if common == []:
    print(1)
else:
    print(reduce(lambda x,y:x*y, list(map(lambda x,y:x ** y, common, common_n))))

Submission status: Accepted

Solution code:
def gcd(x,y):
    if x<y:
        z=x
        x=y
        y=z
    while True:
        if x%y==0:
            break
        else:
            z=x%y
            x=y
            y=z
    return y

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

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())
assert 1 <= x and x <= 10000000000, "xは範囲外です"
assert 1 <= y and y <= 10000000000, "yは範囲外です"
if x == y:
    print(x)
elif x == 0 or y == 0:
    print(0)
else:
    if x < y:
        (x, y) = (y, x)
    d = calc_gcd(x, y)
    print(d)

Submission status: Accepted

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

X, Y = map(int, input().split())
print(gcd(X, Y))

Submission status: Accepted

Solution code:
def greatestdivisor(x, y):
    if y>x:
        tmp = x
        x = y
        y = tmp
        
    while y>0 :
        r = x%y
        x = y
        y = r
    print(x)
    
A=input().split(" ")
greatestdivisor(int(A[0]), int(A[1]))

Submission status: Accepted

Solution code:

m, n = map(int,input().split())

r = m % n

while r != 0:
    m = n
    n = r
    r = m % n 

print(n)

Submission status: Accepted

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


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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(y)

Submission status: Accepted

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

z = x % y

while True:
    if z==0:
        print(y)
        break
    temp = z
    z = y % z
    y = temp
    #print("loop y,z:",y,z)

Submission status: Accepted

Solution code:

def gcd(a,b):
    if a == 0:
        return b
    if a < b:
        a,b=b,a
    #a>=bになった

    return gcd(a%b,b)

inputs=input().split()

print(gcd(int(inputs[0]), int(inputs[1])))

Submission status: Accepted

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

print(gcd(A, B))

Submission status: Accepted

Solution code:
#coding: utf-8

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

x = max(a, b)
y = a + b - x

while x % y > 0:
    z = x % y
    x = y
    y = z
print(str(y))

Submission status: Accepted

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

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

print(gcd(x, y))

Submission status: Accepted

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

def main():
	x,y = map(int,input().split())
	print(gcd(x,y))
	return

main()

Submission status: Accepted

Solution code:
# coding: utf-8

def greatest_common_devisor(x, y):
    if x > y:
        x, y = y, x
    
    amari = y % x

    while amari != 0:
        y = amari # 大きい方を消して，小さい方を残す
        if x > y:
            x, y = y, x
        amari = y % x
    print(x)

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

Submission status: Accepted

Solution code:
"""import math
x,y=map(int,input().split())
print(math.gcd(x,y))"""
x,y=sorted(list(map(int,input().split())))
r=x
while 1:
    if x%y==0:break
    r=x%y
    x=y
    y=r
print(r)

Submission status: Accepted

Solution code:
# 1_1_B_GreatestCommonDivisor.py

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

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

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

print(y)

Submission status: Accepted

Solution code:
def GCD(p,q):
    if p<q:p,q=q,p
    if p%q==0:
        return q
    else:
        return GCD(q,p%q)

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

Submission status: Accepted

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

    return gcd(b % a, a)


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

Submission status: Accepted

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

n=list(map(int,input().split()))
if n[0]==n[1]:
  print(gc(n[0],n[1]))
elif n[0]>n[1]:
  a=n[0]%n[1]
  print(gc(n[1],a))
else:
  a=n[1]%n[0]
  print(gc(n[0],a))

Submission status: Accepted

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

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

    return x
    
print(gcd(a,b))

Submission status: Accepted

Solution code:
# ALDS1_1_B - Greatest Common Divisor
def gcd(x: int, y: int) -> int:
    while x % y:
        x, y = y, x % y
    return y


def main():
    A, B = tuple(map(int, input().split()))
    ans = gcd(A, B)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def euc(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return euc(b%a, a)
if __name__ == '__main__':
    a, b = map(int,input().split())
    print(euc(a, b))

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
b = max(x, y)
s = min(x, y)
c = b % s
while c != 0:
  b = s % c
  b, s, c = s, c, b
print(s)

Submission status: Accepted

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

print(x)

Submission status: Accepted

Solution code:
x, y = [int(x) for x in input().split()]

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


gcd(x,y)

Submission status: Accepted

Solution code:
def test():

	inputs = list(map(int,input().split()))
	
	if inputs[0] > inputs[1]:
		a = inputs[0]
		b = inputs[1]
	else:
		a = inputs[1]
		b = inputs[0]

	while b > 0:

		r = a % b
		a = b
		b = r

	print(a)


if __name__ == "__main__":
	test()

Submission status: Accepted

Solution code:
def f(a,b):
    return a if b==0 else f(b,a%b)
n,m=map(int,input().split())
print(f(n,m))

Submission status: Accepted

Solution code:
Z= input().split()
X=int(Z[0])
Y=int(Z[1])
while(X!=Y):
    if(X>Y):
        R=X-Y
        X=Y
        Y=R
    elif(X<Y):
        R=Y-X
        Y=R
print(Y)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,y=map(int,raw_input().split())
a=0
if x<y:
	x,y=y,x

while True:
	a=x%y
	if a==0:
		a=y
		break
	elif x%a==0 and y%a==0:
		break
	x=y
	y=a
	
print a

Submission status: Accepted

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


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

Submission status: Accepted

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

import sys
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

Submission status: Accepted

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

def GCD(x,y):
    if y > x:
        x,y = y, x
    r = x % y
    while x % y > 0:
        r = x % y
        x = y
        y = r
    return y

print(GCD(x,y))

Submission status: Accepted

Solution code:
def Input():
    data = list(map(int,input().split()))
    return data

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

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

Submission status: Accepted

Solution code:
def gcd(x,y):
    if x%y==0: return y
    else     : return gcd(y,x%y)
 
if __name__=='__main__':
   x,y=list(map(int,input().split())) 
   print(gcd(x,y))

Submission status: Accepted

Solution code:
from math import gcd
  
n, m = map(int, input().split())
print(gcd(n, m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
def calc_gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    return calc_gcd(b,a%b)
 
 
A,B = map(int,input().split())
print("%d"%(calc_gcd(A,B)))

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
def gcd(x,y):
    if x==y:
        return x
    elif x>y:
        r=-1
        while r!=0:
            r=x%y
            x=y
            y=r
        return x
    else:
        r=-1
        while r!=0:
            r=y%x
            y=x
            x=r
        return y
print(gcd(x,y))

Submission status: Accepted

Solution code:
from math import gcd
 
n, m = map(int, input().split())
print(gcd(n, m))

Submission status: Accepted

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

Submission status: Accepted

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

A, B = map(int, input().split())
print(gdc(A, B))

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
while x != y:
  if x > y:
    x -= y
  else:
    y -= x
print(x)

Submission status: Accepted

Solution code:
def getGCD(a, b): # ユークリッドの互除法
    if a < b:
        a, b = b, a
    c = a % b
    if c == 0:
        return b
    else:
        return getGCD(b, c)

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

Submission status: Accepted

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

Submission status: Accepted

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

if x<y:
    str=x
    x=y
    y=str
while True:
    r=x%y
    x=y
    y=r
    if r==0:
        print(x)
        break

Submission status: Accepted

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

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

z = 0
if x < y:
    z = gcd(y, x)
else:
    z = gcd(x, y)

print(z)

Submission status: Accepted

Solution code:
def culc(x, y):
    if x > y:
        n_large = x
        n_small = y
    else:
        n_large = y
        n_small = x

    while True:
        # print("L:%d, S:%d" % (n_large, n_small))
        n_remainder = n_large % n_small
        if n_remainder == 0: break
        n_large = n_small
        n_small = n_remainder

    return n_small

if __name__ == "__main__":

    num = input().split(" ")
    x = int(num[0])
    y = int(num[1])

    print(culc(x, y))

Submission status: Accepted

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

Submission status: Accepted

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

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

while y > 0:
    X = x
    Y = y
    x = Y
    y = X % Y
print(x)

Submission status: Accepted

Solution code:
def GCD(x, y):
    if x < y:
        if y % x == 0:
            print(str(x))
        else :
            GCD(x, y%x)
    elif x > y:
        if x % y == 0:
            print(str(y))
        else :
            GCD(y, x%y)
    else :
        print(str(x))

if __name__ == '__main__':
    a, b = map(int, input().split())
    GCD(a, b)

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

# def printA(A):
#     for i, n in enumerate(A):
#         print(n, end='')
#         if i != N-1:
#             print(' ', end='')
#     print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d


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

print(mymath.gcd(x, y))

Submission status: Accepted

Solution code:
if __name__=='__main__':
    a, b = tuple(map(int, input().split(' ')))
    x = min([a, b])
    y = max([a, b])
    while True:
        x, y = y%x, x
        if x == 0:
            break
    print(y)

Submission status: Accepted

Solution code:
def find_gcd(a: int, b: int) -> int:
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return find_gcd(b, a % b)


if __name__ == "__main__":
    a, b = list(map(lambda x: int(x), input().split()))
    print(f"{find_gcd(a, b)}")

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a

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


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

Submission status: Accepted

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

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

while True:
	if y==0:
		break
	x,y=y,x%y
print(x)

Submission status: Accepted

Solution code:
from sys import stdin
a, b = [int(_) for _ in stdin.readline().rstrip().split()]

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
def euclidean(x, y):
    if y > x:
        x, y = y, x
    while y > 0:
        x_tmp = x
        y_tmp = y
        
        x = y_tmp
        y = x_tmp % y_tmp
    
    return x
        

xy = input().split()
x = int(xy[0])
y = int(xy[1])

print(euclidean(x, y))