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:
# ALDS1_1_B.py
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


N, M = map(int, input().split())
print(gcd(N, M))

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
import functools

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

Submission status: Accepted

Solution code:
from fractions import gcd

a,b = (int(x) for x in input().split())
ans = gcd(a,b)
print(ans)

Submission status: Accepted

Solution code:
x,y = map(int, input().split())
mx =  max(x,y)
mn = min(x,y)

def GCD(large, small):
    if small == 0:
        return large;
    else:
        return GCD(small, large%small)


print(GCD(mx, mn))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(x: int, y: int) -> int:
    if x % y == 0:
        return y
    return gcd(y, x % y)


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    x, y = LI()

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

    print(gcd(x, y))

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

def gcd(x, y):
    new_x = max(x, y)
    new_y = min(x, y)
    while new_y > 0:
        r = new_x % new_y
        new_x = new_y
        new_y = r
    return new_x

print(gcd(x, y))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(a,b):
    if a<b:
        a,b=b,a#swap(最初に確認のswap)
    while b>0:
        a=a%b
        a,b=b,a#(毎回入れ替えるawap)
    return a
A = list(map(int, input().split()))

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

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())


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


print(gcd(x, y))

Submission status: Accepted

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

    return x

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,y  = list(map(int,input().split()))
if x < y:
    dummy = x
    x=y
    y=dummy
while x % y != 0:
    z = x%y
    x = y
    y = z
print(y)

Submission status: Accepted

Solution code:
def euclid(x : int , y : int):
    if y > x:
        x , y = y , x
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

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

Submission status: Accepted

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

if x == y:
    print(x)
else:
    while not (x == 1 and y == 1):
        if x > y:
            x = x % y
            if x == 0:
                print(y)
                break
            # print(f'{x} {y}')
        elif x < y:
            y = y % x
            if y == 0:
                print(x)
                break
            # print(f'{x} {y}')
    '''
    else:

        # xの約数を算出
        divisor_x = []
        for a in range(x):
            if x % (a+1) == 0:
                divisor_x.append(a+1)

        for a in divisor_x[::-1]:
            if y % a == 0:
                print(a)
                break
    '''

Submission status: Accepted

Solution code:
# ユークリッドの互除法
def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x%y
    return x


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
li = list(map(int,input().split()))
li.sort(reverse=True)
while li[0] % li[1] != 0:
  temp = li[1]
  li[1] = li[0] % li[1]
  li[0] = temp
print(li[1])

Submission status: Accepted

Solution code:
import sys
import math
import itertools

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

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

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

  print(gcd(x,y))


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import math #mathモジュールをインポートする。
num_list = list(map(int,input().split())) #2の数をint型にしてリストのにインプットする
print(math.gcd(num_list[0],num_list[1])) #2つの数の最大公約数をとる

Submission status: Accepted

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

while x != y:
    if x < y:
        w = x
        x = y
        y = w
    x = x % y
    if x == 0:
        break

print(y)

Submission status: Accepted

Solution code:
inparray = list(map(int, input().split()))
inparray.sort(reverse=True)
a, b = inparray[0], inparray[1]

while True:
#	print(' {0} {1}'.format(a,b))
	if a % b == 0:
		print(b)
		exit(0)
	else:
		a, b = b, a % b

Submission status: Accepted

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

while b > 0:
    if a < b:
        a, b = b, a
    a, b = b, a % b
print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

print(math.gcd(x, 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()]
ans = gcd(x, y)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
if x<y:
    x,y=y,x
while y>0:
    v=y
    y=x%y
    x=v
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
    print(x)

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

Submission status: Accepted

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

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

main()

Submission status: Accepted

Solution code:
# ALDS1_1_B: Greatest Common Divisor
import sys
x, y = map(int, sys.stdin.readline().strip().split())


def gcd(x, y):
    if x <= y:  # x のほうが
        x, y = y, x

    r = -1
    while r != 0:
        r = x % y
        x = y
        y = r
    return x


print(gcd(x, y))

Submission status: Accepted

Solution code:

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

while y != 0:
    if x >= y:
        x,y = y,x%y
    else:
        x,y = y,x

print(x)

Submission status: Accepted

Solution code:

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


num = input("")
lst_num = num.split()
print(generate_number(int(lst_num[0]),int(lst_num[1])))

Submission status: Accepted

Solution code:
def sub_GCD(x, y):
    if x > y:
        return y, x % y
    else:
        return x, y % x

def GCD(x, y):
    while not (x==0 or y==0):
        x, y = sub_GCD(x, y)
    print(x)

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

Submission status: Accepted

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

def divs(n:int):
    divs = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    return divs

print (max(set(divs(x))&set(divs(y))))

Submission status: Accepted

Solution code:

def gcd(a,b):
  if a % b == 0:
    return b
  else:
    return gcd(b,a % b)
    
x, y = map(int,input().split())
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:
import math
a,b = map(int, input().split())
print(math.gcd(a,b))

Submission status: Accepted

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

if b > a:
    a, b = b, a

mod = 1
while mod > 0:
    mod = a % b
    
    a = b
    b = mod

print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

from math import gcd

print(gcd(x, y))

Submission status: Accepted

Solution code:
x,y = map(int, input().split())
b = min((x, y))
a = max((x, y)) % b
if a == 0:
    print(b)
else:
    for i in range(1, a + 1):
        if a % i == 0 and b % (a / i) == 0:
            print(int(a / i))
            break

Submission status: Accepted

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

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

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

    if temp == 0:
        break
    x = y
    y = temp

print(str(y))

Submission status: Accepted

Solution code:
# Problem 1 - 最大公約数

def gcd(a, b):
    if a<b:
        tmp = a
        a = b
        b = tmp
    while b>0:
        r = a % b
        a = b
        b = r
    return a

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

# output
print(gcd(a, b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def gcd(x, y):
                if y == 0:
                                return x
                else:
                                x %= y  # xをyで割った余りをxに代入。
                                x, y = y, x  # xとyの中身を入れ換え。
                                return gcd(x, y)
print(gcd(a, b))

Submission status: Accepted

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

if __name__ == "__main__":
    import sys
    input = sys.stdin.readline # faster input

    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 x%y != 0:
    z = x%y
    x = y
    y = z
print(y)

Submission status: Accepted

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

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

Submission status: Accepted

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

bigger = max(a,b)
smaller = min(a,b)
resid = smaller
while resid != 0:
    smaller = resid
    resid = bigger%smaller
    bigger = smaller
print(smaller)

Submission status: Accepted

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

while x:
    y, x = x, y%x
print(y)

Submission status: Accepted

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

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

Submission status: Accepted

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


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

main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
while(y>0):
    a=x
    x=y
    y=a%y
    #print("{},{}".format(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
    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:
x=[int(x) for x in input().split()]
if x[0] >x[1]:
    a, b = x[0], x[1]
else:
    a, b = x[1], x[0]
while(True):
    c=a%b
    if c==0:
        print(b)
        break
    a=b
    b=c

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
a = [min(a), max(a)]

while True:
    if a[0] % a[1] == 0:break
    a = [min(a), max(a) % min(a)]
print(a[1])

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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)

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

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
initx=x
inity=y
while True:
    if x<y:
        x,y=y,x#常にx>yにしたい
    pre_gcd=x%y
    if pre_gcd==0:
        print(y)
        break
    elif initx%pre_gcd==0 and inity%pre_gcd==0:
        print(pre_gcd)
        break
    x=pre_gcd

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
x, y = map(int, input().split())
# if (x < y):
#     x, y = y, x
# while (x % y != 0):
#     x, y = y, x % y

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

Submission status: Accepted

Solution code:
def gcd(a,b):
    if a%b==0:
        return b
    if a<b:
        a,b=b,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())


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


print(gcd(x, y))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())

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

gcd(n,m)

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:
def gojo(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(gojo(x,y))

Submission status: Accepted

Solution code:
def find_gcd(a, b):
    '''
    a >= b
    '''
    if a % b == 0:
        return b
    else:
        return find_gcd(b, a % b)


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

a = max(li)
b = min(li)

div = find_gcd(a, b)
print(div)

Submission status: Accepted

Solution code:

import math

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

print(math.gcd(a, b))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,y = map(int,input().split())
if y>x:
    x,y = y,x
r = x-y
b = 0
while True:
    b = abs(y-r)
    y = r
    r = b
    if r ==y:
        break
print(y)

Submission status: Accepted

Solution code:
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while b:
        a, b = b, a % b
    return a


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

Submission status: Accepted

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

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

print(gcd(x,y))

Submission status: Accepted

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

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

gcd = x
while(y % x != 0):
    gcd = y % x
    y = x
    x = gcd
print(gcd)

Submission status: Accepted

Solution code:
from math import gcd

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 % y != 0:
    tmp = y
    y = x % y
    x = tmp
    
print(y)

Submission status: Accepted

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

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

print(gcd(a,b))

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)
    
a,b = map(int,input().split())
print(calc_gcd(a,b))

Submission status: Accepted

Solution code:
def get_input():
    return map(lambda s: int(s), input().split(' '))

def swap(a, b):
    if a < b:
        return (a, b)
    else:
        return (b, a)

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

    return b

print(gcd(*swap(*get_input())))

Submission status: Accepted

Solution code:
a, b = [int(item) for item in input().split()]

def gcd(a, b):
    
    while b > 0:
        a, b = b, a%b
        # print(a, b)
    return a

print(gcd(a, b))

Submission status: Accepted

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

x, y = map(int, input().split())
if y > x:
    x, y = y, x

print(gcd(x, y))

Submission status: Accepted

Solution code:
a, b = [int(i) for i in input().split(" ")]

r = a % b
while r > 0 :
    a = b
    b = r
    r = a % b
print(b)

Submission status: Accepted

Solution code:
import math

n,m = map(int, input().split())
ans = math.gcd(n,m)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
print(eval("math.gcd(" + ",".join(input().split()) + ")"))

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
def GCD(x,y):
    a = x%y
    while a != 0:
        x = y
        y = a
        a = x%y
    return y

L = input().split()
L = [int(L[0]),int(L[1])]
L = sorted(L)
x = L[0]
y = L[1]

print(GCD(x,y))

Submission status: Accepted

Solution code:
A = list(map(int,input().split()))
a = 1
k = 0
b = 0

if A[0]>A[1]:
    k = A[1]
    A[1] = A[0]
    A[0] = k

while a != 0:
    a = A[1]%A[0]
    if a==0:
        print(A[0])
    A[1] = A[0]
    A[0] = a

Submission status: Accepted

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

x, y = map(int, input().split())
if x < y:
   x, y = y, x
gcd = GreatestCommonDivisor(x, y)
print(gcd)

Submission status: Accepted

Solution code:
# ２つの整数 x と y について、x ÷ d と y ÷ d の余りがともに 0 となる d のうち最大のものを、x と y の最大公約数（Greatest Common Divisor）と言います。
# 例えば、35 と14 の最大公約数 gcd (35, 14) は 7 となります。これは、35 の約数{1, 5, 7, 35}、14 の約数 {1, 2, 7, 14} の公約数 {1, 7} の最大値となります。

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


# 147 % 105 = 42
# 105 % 42 = 21
# 42 % 21 = 2

mod = 0
while True:
    mod = max(x, y) % min(x, y)
    x  = y
    y = mod
    if mod <= 0: break
    
print(x)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ユークリッドの互除法

def euclid(x, y):
    return y if not x%y else euclid(y, x%y)

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

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

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

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

Submission status: Accepted

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

    while True:
        r = a % b

        if r == 0:
            print(b)
            break

        a, b = b, r

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

    if a < b:
        a, b = b, a

    gcd(a, b)

main()

Submission status: Accepted

Solution code:
#アルゴリズムの実装
def greatest_common_divisor(x, y):
    if x == y:
        return x
    elif x > y:
        while True:
            x, y = y, x % y
            if y == 0: break
        return x
    else:
        x, y = y, x
        while True:
            x, y = y, x % y
            if y == 0: break
        return x

#入力dataの挿入
input_data = list(map(int, input().split()))

#処理の実行
result = greatest_common_divisor(input_data[0], input_data[1])
print(result)

Submission status: Accepted

Solution code:
from math import gcd

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

Submission status: Accepted

Solution code:
# Algorithms and Data Structures 1
# Greatest Common Divisor
# Name: Ryuya Asada
# ID: s1260064


def gcd(a: int, b: int) -> int:
    if b == 0:
        return a
    
    return gcd(b, a%b)


def main():
    a, b = (int(e) for e in input().split(" "))
    print(gcd(a, b))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 入力
data = list(map(int, input().split()))

# 大きい方を判別
max_i = 0
min_i = 1
if data[0] < data[1]:
    max_i = 1
    min_i = 0

a = data[min_i]

# 大きい数を小さい数で悪る
b = data[max_i] % a

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

print(a)

Submission status: Accepted

Solution code:
x, y = [int(i) for i in input().split()]
if y > x:
    x, y = y, x
while y != 0:
    x, y = y, x % y
print(x)

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
if x >= y:
    while True:
        a,b = divmod(x,y)
        if b == 0:
            print(y)
            break
        else:
            x = y
            y = b
elif x < y:
    while True:
        a,b = divmod(y,x)
        if b == 0:
            print(x)
            break
        else:
            y = x
            x = b

Submission status: Accepted

Solution code:
#GCD

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

# xの方が大きくなくてはならない
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:
def gcd(x, y):
    if x < y:
        gcd(y, x)
        return

    while y > 0:
        m = x % y
        x = y
        y = m
    print(x)


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

Submission status: Accepted

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

Submission status: Accepted

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

while x % y != 0:
    div = x % y
    x = y
    y = div
    # print('{} {}'.format(x, y))

print(y)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if a < b:
    x = b
    y = a
else:
    x = a
    y = b

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

print(x)

Submission status: Accepted

Solution code:
def gcd(x,y):
	if x < y:
		y,x = x,y
	if x%y ==0:
		return y
	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()))
while not x == 0:
    m = min(x, y)
    x = max(x, y) % m
    y = m
print(y)

Submission status: Accepted

Solution code:
def help(a):
    x = a[0] % a[1]
    a[0] = a[1]
    a[1] = x
    return a

a = list(map(int, input().split()))
if a[0]<a[1]:
    tmp = a[0]
    a[0] = a[1]
    a[1] = tmp

while a[1]>1:
    help(a)
if a[1]==0:
    print(a[0])
else:
    print(a[1])

Submission status: Accepted

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

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

print(gcd(a, b))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

r = euclid(x,y)
print(r)

Submission status: Accepted

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

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 == 0:
        return y
    elif x >= y:
        return gcd(y, x%y)
    else:
        return 1

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

Submission status: Accepted

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

while (y):
    x,y = y,x%y

print(x)

Submission status: Accepted

Solution code:
def gcd(a, b):
    r1 = a
    r2 = b
    while True:
        r = r1 % r2
        if r == 0:
            return r2
        else:
            r1 = r2
            r2 = r

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

Submission status: Accepted

Solution code:
a,b = [int(i) for i in input().split()]
while a%b != 0:
    a, b = b, a%b
print(b)

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:
x,y=map(int,input().split())
x,y=max(x,y),min(x,y)
while(y!=0):
	x,y=y,x%y
print(x)

Submission status: Accepted

Solution code:
def gcd(x,y):
    if x < y:
        x1 = x
        x = y
        y = x1
    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:
        x,y = y,x
    
    while y > 0:
        r = x % y
        x = y
        y = r
    
    print(x)    


nums=list(map(int,input().split()))
gcd(nums[0], nums[1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A = [list(map(int, s.split())) for s in open(0)][0]
x, y = A[0], A[1]
if y > x:
    l, s = y, x
else:
    l, s = x, y
while l % s >  0:
    m = l % s 
    l = s 
    s = m
print(s)

Submission status: Accepted

Solution code:

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

def greatest_common_divider(x, y):
  while y > 0:
    n = x % y
    x = y
    y = n
  return x

print(greatest_common_divider(x, y))

Submission status: Accepted

Solution code:
def gcd(a, b):
    mod = max(a, b) % min(a, b)
    if mod == 0:
        print(b)
    else:
        gcd(min(a, b), mod)

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