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: Runtime Error

Solution code:
a = list(map(int, input().split()))
t , u = a[0],a[1]

def c(x,y):
  if x % y:
    return(c(y,x%y))
  else:
    return(y)

print(u//20)

Submission status: Runtime Error

Solution code:
import math
a=read().split()
b=list(map(int,a))
print(math.gcd(b[0],b[1]),\n)

Submission status: Runtime Error

Solution code:
import math
a=read()
b=a.split
print(math.gcd(int(b[0]),int(b[1])),\n)

Submission status: Runtime Error

Solution code:
x, y = [int(x) for x in input().split()]
def gcd(a,b):
    m = a%b
    return gcd(b,m) if r else n
print(gcd(x,y))

Submission status: Runtime Error

Solution code:
line=input().split()
x=int(line[0])
y=int(line[1])
r=x%y
while(r>0):
    x=y
    y=r
    r=x%y
return y

print(y)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
list=[int(i) for i in input().split()]

a=list[0]
b=list[1]

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

print(c)

Submission status: Runtime Error

Solution code:
line=input().split()
x=int(line[0])
y=int(line[1])
if x<y:
    temp=x
    x=y
    y=temp
def greatst(x,y):
    if x==y:
        return x
    else:
        return greatst(y,x%y)
print(greatst(x,y))

Submission status: Runtime Error

Solution code:
list=[int(i) for i in input().split()]

if list[0]>list[1]:
    a=list[0]
    b=list[1]
else:
    b=list[0]
    a=list[1]    

if a%b==0:
    print (b)
else:
    while a%b!=0:
        c=a%b
        a=b
        b=c

print(c)

Submission status: Runtime Error

Solution code:
list=[int(i) for i in input().split()]

if list[0]>list[1]:
    a=list[0]
    b=list[1]
else:
    b=list[0]
    a=list[1]    

if a%b==0:
    print (b)
else:
    while a%b!=0:
        c=a%b
        a=b
        b=c

    print(c)

Submission status: Runtime Error

Solution code:
list=[int(i) for i in input().split()]

if list[0]>list[1]:
    a=list[0]
    b=list[1]
else:
    b=list[0]
    a=list[1]    


if a%b==0:
    print (b)
else:
    while b>0:
        c=a%b
        a=b
        b=c

print(a)

Submission status: Runtime Error

Solution code:
list=[int(i) for i in input().split()]

if list[0]>list[1]:
    a=list[0]
    b=list[1]
else:
    b=list[0]
    a=list[1]    


if a%b==0:
    print (b)
else:
    while b>0:
        c=a%b
        a=b
        b=c

    print(b)

Submission status: Runtime Error

Solution code:
list=[int(i) for i in input().split()]

if list[0]>list[1]:
    a=list[0]
    b=list[1]
else:
    b=list[0]
    a=list[1]    


if a%b==0:
    print (b)
else:
    while b>0:
        c=a%b
        a=b
        b=c
        

    print(a)

Submission status: Runtime Error

Solution code:
# 16D8101022L 小林勇希 ID:k_mb python3

def GCD(x,y):
    if(x >= y):
        z = y
        w = x%y
    else:
        z = x
        w = y%x
    if(w != 0):
        GCD(z,w)
    else:
        print(z)

a = int(input())
b = int(input())
GCD(a,b)

"""実行結果

100
55
5



66
77
11

"""

Submission status: Runtime Error

Solution code:
def GCD(x,y):

    if(x >= y):
        z = y
        w = x%y
    else:
        z = x
        w = y%x

    while(1):
        if(w != 0):
            v = w
            w = z%w
            z = v
        else:
            print(z)
            break
"""
    if(w != 0):
        if(x >=y)
        GCD(z,w)
    else:
        print(z)
"""

a = int(input())
b = int(input())
GCD(a,b)

Submission status: Runtime Error

Solution code:
def GCD(x,y):

    if(x >= y):
        z = y
        w = x%y
    else:
        z = x
        w = y%x

    if(not(w == 0)):
        GCD(z,w)
    else:
        print(z)

a = int(input())
b = int(input())
GCD(a,b)

Submission status: Runtime Error

Solution code:
# 16D8101022L 小林勇希 ID:k_mb python3

def GCD(x,y):

    if(x >= y):
        z = y
        w = x%y
    else:
        z = x
        w = y%x

    if(not(w == 0)):
        return GCD(z,w)
    else:
        print(z)
"""

    while(1):
        if(w != 0):
            v = w
            w = z%w
            z = v
        else:
            print(z)
            break
"""


a = int(input())
b = int(input())
GCD(a,b)

Submission status: Runtime Error

Solution code:
# 16D8101022L 小林勇希 ID:k_mb python3

def GCD(x,y):

    if(x >= y):
        z = y
        w = x%y
    else:
        z = x
        w = y%x

    if(not(w == 0)):
        return GCD(z,w)
    else:
        return z
"""

    while(1):
        if(w != 0):
            v = w
            w = z%w
            z = v
        else:
            print(z)
            break
"""


a = int(input())
b = int(input())
print(GCD(a,b))

Submission status: Runtime Error

Solution code:
def GCD(x,y):

    if(x >= y):
        z = y
        w = x%y
    else:
        z = x
        w = y%x

    if(not(w == 0)):
        return GCD(z,w)
    else:
        return z

a = int(input())
b = int(input())
print(GCD(a,b))

Submission status: Runtime Error

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



a = int(input())
b = int(input())
print(gc(a,b))

Submission status: Runtime Error

Solution code:
def GCD(x,y):

    if(x >= y):
        z = y
        w = x%y
    else:
        z = x
        w = y%x

    if(not(w == 0)):
        return GCD(z,w)
    else:
        return z

A = [int() for i in input().split()]
print(GCD(A[0],A[1]))

"""実行結果

100 55
5



66 77
11

"""

Submission status: Runtime Error

Solution code:
import numpy as np

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


A=list(map(int,input().split(' ')))

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

Submission status: Runtime Error

Solution code:
def isprime(x):
	n=3
	X = 0
	if x ==2:
		return 1
	if x < 2 or x%2 == 0:
		return 0
		n = 3
		X = math.sqrt(x)
	while(3<=X):
		if x % i == 0:
			return 0
		i = i+2
	return 1

n = int(input())
cnt_ans = 0
cnt = 3
A = []
for i in range(0,n):
	   a = int(input())
	   A.append(a)
for i in range(0,n):	   
    cnt = isprime(A[i])	   	
    if cnt == 1:
       	cnt_ans = cnt_ans + 1
        cnt = 3 
print (cnt_ans)

Submission status: Runtime Error

Solution code:

n = [int(i) for i in input().split()]

x = n[0]
y = n[1]

d = x % y

while(d != 0):

    x = y
    y = d
    d = x % y

print(y)

Submission status: Runtime Error

Solution code:
n = [int(i) for i in input().split()]

x = n[0]
y = n[1]

d = x % y

while d != 0:

    x = y
    y = d
    d = x % y

print(y)

Submission status: Runtime Error

Solution code:
#include<stdio.h>

int main(void)
{
	int x, y, d;

	scanf("%d", &x);
	scanf("%d", &y);

	d = x % y;

	while (d != 0){
		x = y;
		y = d;
		d = x % y;
	}
	printf("%d\n", y);
	
	return 0;
}

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b==0:
        return a
    c=a%b
    return gcd(b,c)
x=int(input("x:"))
y=int(input("y:"))
if x<y:
    x,y=y,x
m=gcd(x,y)
print(m)
def gcd(x,y):

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b==0:
        return a
    c=a%b
    return gcd(b,c)
x=int(input("x:"))
y=int(input("y:"))
if x<y:
    x,y=y,x
m=gcd(x,y)
print(m)
def gcd(x,y):
    if b==0:
        return a
    return gcd(b,c)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b==0:
        return a
    c=a%b
    return gcd(b,c)
x=int(input(""))
y=int(input(""))
if x<y:
    x,y=y,x
m=gcd(x,y)
print(m)
def gcd(x,y):

Submission status: Runtime Error

Solution code:
x=input()
y=input()
x=int(x)
y=int(y)
xg=set()
yg=set()
for i in range(1,x+1):
    if x%i==0:
        xg.add(i)
for j in range(1,y+1):
    if y%j==0:
        yg.add(j)
gcd=xg & yg
print(max(gcd))

Submission status: Runtime Error

Solution code:
x,y=map(int,input().split())
ma=max(x,y)
for i in range(1,ma):
    if x%i==0 or y%i==0:
        gcd=i
print(max(gcd))

Submission status: Runtime Error

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

flag = True
counter = 0
while flag:
    flag = False
    for i in range(N-1, 0, -1):
        if A[i-1] > A[i]:
            A[i], A[i-1] = A[i-1], A[i]
            flag = True
            counter += 1

print(' '.join(map(str, A)))
print(counter)

Submission status: Runtime Error

Solution code:
l = [int(s) for s in l]
for i in range(1,l[0]):
    if l[0] % i == 0 and l[1] % i == 0:
        c = i
print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
def gcd_loop(a,b):
    if a < 0: a = -a
    if b < 0: b = -b
    if b < a: b, a = a, b
    if a == 0:
        return b
    while True:
        if b%a == 0:
            return a
        a, b = b%a, a


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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

for line in sys.stdin:
    A=line.split()
    B=map(int,A)

B=B.sort()

while B[1]%B[0] != 0:
    C=B[0]
    B[0]=B[1]%B[0]
    B[1]=C

print B[0]

Submission status: Runtime Error

Solution code:
import sys

for line in sys.stdin:
    A=line.split()
    B=map(int,A)

D=B.sort()
e=1

while e != 0:
    e=B[1]%B[0]
    C=[0]
    B[0]=e
    B[1]=C

print B[0]

Submission status: Runtime Error

Solution code:
import sys

for line in sys.stdin:
    A=line.split()
    B=map(int,A)

D=B.sort()
e=1

while e != 0:
    e=D[1]%D[0]
    C=[0]
    D[0]=e
    D[1]=C

print D[0]

Submission status: Runtime Error

Solution code:
import sys

for line in sys.stdin:
    A=line.split()
    B=map(int,A)

D=B.sort()
e=1

while e != 0:
    e=D[1]%D[0]
    C=[0]
    D[0]=e
    D[1]=C

print e

Submission status: Runtime Error

Solution code:
import sys

for line in sys.stdin:
    A=line.split()
    B=map(int,A)

D=B.sort()
e=1

while e != 0:
    e=D[1]%D[0]
    C=D[0]
    D[0]=e
    D[1]=C

print D[0]

Submission status: Runtime Error

Solution code:
import sys


for line in sys.stdin:
    global B
    A=line.split()
    B=map(int,A)

D=B.sort()
e=1

while e != 0:
    e=D[1]%D[0]
    C=D[0]
    D[0]=e
    D[1]=C

print D[0]

Submission status: Runtime Error

Solution code:
import sys

B=[]

for line in sys.stdin:
    global B
    A=line.split()
    B=map(int,A)

D=B.sort()
e=1

while e != 0:
    e=D[1]%D[0]
    C=D[0]
    D[0]=e
    D[1]=C

print D[0]

Submission status: Runtime Error

Solution code:
import sys

for line in sys.stdin:
    A=line.split()
    B=map(int,A)

    D=B.sort()
    e=1

    while e != 0:
        e=D[1]%D[0]
        C=D[0]
        D[0]=e
        D[1]=C

    print D[0]

Submission status: Runtime Error

Solution code:
import sys

for line in sys.stdin:
    A=line.split()
    B=map(int,A)

    e=1

    while e != 0:
        e=B[0]%B[1]
        C=B[1]
        B[1]=e
        B[0]=C

    print B[0]

Submission status: Runtime Error

Solution code:
import sys

for line in sys.stdin:
    A=line.split()
    B=map(int,A)
    if B[0]<B[1]:
        p=B[1]
        B[1]=B[0]
        B[0]=p
    e=1

    while e != 0:
        e=B[0]%B[1]
        C=B[1]
        B[1]=e
        B[0]=C

    print B[0]

Submission status: Runtime Error

Solution code:
import sys

for line in sys.stdin:
    lineA=line.strip()
    A=lineA.split()
    B=map(int,A)
    if B[0]<B[1]:
        p=B[1]
        B[1]=B[0]
        B[0]=p
    e=1

    while e != 0:
        e=B[0]%B[1]
        C=B[1]
        B[1]=e
        B[0]=C

    print B[0]

Submission status: Runtime Error

Solution code:
a,b = map(float,raw_input().split())
m = a
if a>b:
    m = b
max = 0
for i in range(2,m+1):
    if a % i == 0 and b % i == 0:
        max = i
print max

Submission status: Runtime Error

Solution code:
a,b = map(int,raw_input().split())
m = a
if a>b:
    m = b
max = 0
for i in range(1,m+1):
    if a % i == 0 and b % i == 0:
        max = i
print max

Submission status: WA: Presentation Error

Solution code:
inp=sorted(list(map(int,input().split())))
while inp[1]>=inp[0]:
    a=inp[1]%inp[0]
    if a==0:
        break
    inp[1]=inp[0]
    inp[0]=a

print(inp[0],end='')

Submission status: WA: Presentation Error

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

Submission status: WA: Presentation Error

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import print_function
import time
import sys
import io
import re
import math
#start = time.clock()
#h,i = 497,284
h,i=map(int, raw_input().split())


while i != 0:
    siki= h % i
    h = i
    i = siki

print (h, end='')