Problem:


Score : 200 points

Problem Statement

You are given positive integers A and B.

Find the K-th largest positive integer that divides both A and B.

The input guarantees that there exists such a number.

Constraints

All values in input are integers.

1 \leq A, B \leq 100

The K-th largest positive integer that divides both A and B exists.

K \geq 1

Input

Input is given from Standard Input in the following format:

A B K

Output

Print the K-th largest positive integer that divides both A and B.

Sample Input 1

8 12 2

Sample Output 1

2

Three positive integers divides both 8 and 12: 1, 2 and 4.
Among them, the second largest is 2.

Sample Input 2

100 50 4

Sample Output 2

5

Sample Input 3

1 1 1

Sample Output 3

1



Sample input:
8 12 2


Sample output:
2

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(A: int, B: int, K: int):
    d = gcd(A, B)
    return [i for i in range(1, d + 1) if (d % i) == 0][-K]


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    result = solve(A, B, K)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,k=(int(i) for i in input().split())
x=[]
for i in range(100,0,-1):
  if (a%i==0)and(b%i==0):
    x.append(i)
print(x[k-1])

Submission status: Accepted

Solution code:
a=[0,0]
s=[]
a[0],a[1],k=map(int,input().split())
for i in range(1,min(a)+1):
  if a[0]%i==0 and a[1]%i==0:
    s.append(i)
print(s[len(s)-k])

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
n=a
while c:
    if a%n==b%n==0:
        c-=1
    n-=1
print(n+1)

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())

if A < B:
    tmp = A
    A = B
    B = tmp

numA = []
for i in range(A+1,0,-1):
    if A % i == 0 :
        numA.append(i)

count = 0
for j in range(len(numA)):
    if B % numA[j] == 0:
        count += 1
        if count == K:
            print(numA[j])
            break

Submission status: Accepted

Solution code:
import fractions

a, b, k = map(int, input().split())
gcd = fractions.gcd(a, b)
divisor_list = []

if gcd == 1:
    divisor_list = [1]
else:
    divisor_list.append(1)
    for i in range(2, gcd // 2 + 1):
        if gcd % i == 0:
            divisor_list.append(i)
    divisor_list.append(gcd)

print(divisor_list[len(divisor_list)-1-k+1])

Submission status: Accepted

Solution code:
[A,B,K] = list(map(int,input().split()))
div = [i for i in range(1,101) if A % i == 0 and B % i == 0]
print(div[-K])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())

l = []
for i in range(1, min(A, B)+1):
    if A % i == 0 and B % i == 0:
        l.append(i)

print(l[-K])

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
ans=[]
for i in range(1,min(a,b)+1):
    if (a%i==0) and (b%i==0):
        ans.append(i)
print(ans[-k])

Submission status: Accepted

Solution code:
from sys import stdin
import fractions

A,B,K = [int(x) for x in stdin.readline().rstrip().split()]

x = fractions.gcd(A,B)

res = []
for i in range(x+1,0,-1):
  if A%i == 0 and B%i == 0:
    res.append(i)

print(res[K-1])

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
A_div = make_divisors(A)
B_div = make_divisors(B)
koyakusu = list(set(A_div) & set(B_div))
koyakusu.sort(reverse=True)
#koyakusu = set(A_div) & set(B_div)
print(koyakusu[K-1])

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
count = K
for i in range(min(A,B),0,-1):
    if A % i == 0 and B % i == 0:
        count -= 1
        if count == 0:
            print(i)
            break

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
da = []
db = []
dc = []
for i in range(1,a+1):
    if a%i == 0:
    	da.append(i)

for j in range(1, b+1):
    if b%j == 0:
    	db.append(j)

for l in da:
    if l in db:
    	dc.append(l)

dc.sort(reverse = True)
print(dc[k-1])

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
count = 0
for i in range(min(a,b),0,-1):
    if (a%i==0)&(b%i==0):
        count += 1
    if count ==k:
        print(i)
        break

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
X = []
for i in range(1,min(A,B) + 1):
    if A % i == 0 and B % i == 0:
        X.append(i)

print(X[-K])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
lists = []
if A < B:
    max = B
else:
    max = A
for i in range(1, max+1):
    if A % i == 0 and B % i == 0:
        lists.append(i)
lists.reverse()
print(lists[K-1])

Submission status: Accepted

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

yakusu = []

for i in range(max(A, B), 0, -1):
    if A % i != 0 or B % i != 0:
        continue
    yakusu.append(i)

print(yakusu[K - 1])

Submission status: Accepted

Solution code:
A,B,K = map(int, input().strip().split(' '))
print([i for i in range(1,min(A,B)+1) if A%i == 0 and B%i == 0][-K])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())

L = []
for i in range(1, max([A, B]) + 1):
	if not A % i and not B % i:
		L.append(i)
print(L[-K])

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
 
ans = []
 
for i in range(1, 101):
    if(a % i == 0 and b % i == 0):
        ans.append(i)
print(ans[-k])

Submission status: Accepted

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

ans = []

for i in range(1, 101):
    if(a % i == 0 and b % i == 0):
        ans.append(i)
print(ans[-k])

Submission status: Accepted

Solution code:
A,B,K = map(int, input().split())
listA = []
listB = []
for i in range(1,A+1):
    if A%i == 0:
        listA.append(i)
for i in range(1,B+1):
    if B%i == 0:
        listB.append(i)
AB = []
for i in range(len(listA)):
    if listA[i] in listB:
        AB.append(listA[i])
print(AB[len(AB)-K])

Submission status: Accepted

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

fA = set([i for i in range(1, A + 1) if A % i == 0])
fB = set([i for i in range(1, B + 1) if B % i == 0])

f = sorted(list(fA.intersection(fB)))
print(f[-K])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
count = 0
for i in range(min(A, B), 0, -1):
    if A % i == B % i == 0:
        count += 1
        if count == K:
            print(i)
            exit()

Submission status: Accepted

Solution code:
# ABC120B - K-th Common Divisor
a, b, k = list(map(int, input().rstrip().split()))
a, b = sorted([a, b])
div = []

for i in range(1, a + 1):
    if a % i == 0 and b % i == 0:
        div.append(i)

print(sorted(div, reverse=True)[k - 1])

Submission status: Accepted

Solution code:
a,b,k = map(int,input().split())
import fractions
n = fractions.gcd(a,b)
divisor = []
for i in range(int(n/2)+1):
  if n % (i+1) == 0:
    divisor.append(i+1)
divisor.append(n)
print(divisor[-k])

Submission status: Accepted

Solution code:
A, B, K = map(int,input().split())

end = min(A,B)
ans = []

for i in range(end):
    i += 1
    if A % i == 0 and B % i == 0:
        ans.append(i)

print(ans[-K])

Submission status: Accepted

Solution code:
A, B, K = map(int,input().split())
Y = []
small = min(A+1,B+1)
for i in range(1,small):
    if A % i == 0:
        if B % i ==0:
            Y.append(i)
print(Y[-K])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split(" "))

c = [] # 公約数のリスト
for i in range(1, max(A, B) + 1):
    if A % i == 0 and B % i == 0:
        c.append(i)

print(c[-K])

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
mx = max(a, b)
match, ans = 0, 0

for i in range(mx):
    if ((a % (mx - i)) == 0) and ((b % (mx - i)) == 0):
        
        match += 1
        ans = mx - i
        
        if match == k:
            break
print(ans)

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
numlst=[]
for i in range(max(a,b)):
    if a%(i+1)==0 and b%(i+1)==0:
        numlst.append(i+1)

print(numlst[len(numlst)-k])

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
cnt = 0
for i in range(100, 0, -1):
  if a % i == 0 and b % i == 0:
    cnt += 1
    if cnt == k:
      print(i)
      break

Submission status: Accepted

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

A, B, K = map(int, input().split())

for i in range(min(A, B), 0, -1):
    if A % i == 0 and B % i == 0:
        K -= 1
        if K == 0:
            print(i)
            break

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())


cnt = 0
for i in range(1, 101)[::-1]:
    if A % i == 0 and B % i == 0:
        cnt += 1
    if cnt == K:
        print(i)
        break

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
l = [0]
for i in range(1, min(a, b)+1):
    if a%i==0 and b%i==0:
        l.append(i)
print(l[-k])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
D = []
for i in range(A, 0, -1):
	if A % i == 0 and B % i == 0:
		D.append(i)
print(D[K - 1])

Submission status: Accepted

Solution code:
import fractions
A, B, K = map(int, input().split())
# はじめにgcd(a, b)を求める
G = fractions.gcd(A, B)
# Gの約数がA, Bの公約数になるのでこれを列挙し、大きい順に並べてK番目を出力
i = 1
divisors = []
while i ** 2 <= G:
	if G % i == 0:
		divisors.append(i)
		divisors.append(G // i)
	i += 1
divisors = sorted(list(set(divisors)))[:: -1]
print(divisors[K - 1])

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
l = []
for i in range(1,101):
    if (A%i)==0 and (B%i)==0:
        l += [i]
print(sorted(l)[-K])

Submission status: Accepted

Solution code:
A, B, K =[int(_) for _ in input().split()]

def cd(a,b,n):
    cnt = 0
    st = min(a,b)
    for i in range(st,0,-1):
        if a % i == 0 and b % i == 0:
            cnt +=1
            if n == cnt:
                return i
print(cd(A,B,K))

Submission status: Accepted

Solution code:
# input
A, B, K = (int(i) for i in input().split())

# main
ans_list = []
for i in range(1, min(A, B) + 1):
    if A % i == 0 and B % i == 0:
        ans_list.append(i)

# output 
ans = ans_list[-K]
print(ans)

Submission status: Accepted

Solution code:
tmp=input().split(" ")
a = int(tmp[0])
b = int(tmp[1])
k = int(tmp[2])

count=0
for n in range(max(a,b), 0, -1):
    if a % n == 0 and b % n == 0:
        count += 1
        if count == k:
            print(n)
            exit()

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
list_w=[]
for i in range(1,101):
    if a%i==0 and b%i==0:
        list_w.append(i)
list_w.reverse()
print(list_w[k-1])

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
i=101
c=0
while(c!=k):
    i-=1
    if a%i==0 and b%i==0:
        c+=1
print(i)

Submission status: Accepted

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

ans = 0
num = 0
for index in range(100):
  i = 100 - index
  if ((a % i) == 0) and ((b % i) == 0):
    num += 1
  if num == k:
    ans = i
    break
print(ans)

Submission status: Accepted

Solution code:
# B - K-th Common Divisor
# https://atcoder.jp/contests/abc120/tasks/abc120_b
# 1WA
MAX = 100

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

A, B, K = map(int, raw_input().split())
gcdAB = gcd(A, B)

cnt = 0
for n in range(gcdAB, 0, -1):
    if gcdAB % n == 0:
        cnt += 1
        if cnt == K:
            print '{}'.format(n)
            break

Submission status: Accepted

Solution code:
[A, B, K] = list(map(int,input().split()))

tmp = 0
i = max(A,B)
while (tmp < K):
    if (A % i == 0) and (B % i == 0):
        tmp += 1
    i -= 1

    
print(i + 1)

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())

aliquots = []
for nominee in range(1,100+1):
	if A % nominee == 0 and B % nominee == 0:
		aliquots.append(nominee)
		
print(aliquots[len(aliquots)-K])

Submission status: Accepted

Solution code:
S = list(map(int, input().split()))
A=S[0]
B=S[1]
K=S[2]
i=1
cnt=0
m=min(A,B)
while True:
    if(A%m==0 and B%m==0):
        cnt+=1
        if(cnt==K):
            print(m)
            exit()
    m-=1

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
n = min(A, B)
list1 =[]
for i in range(1, n+1):
  if A % i == 0 and B % i == 0:
    list1.append(i)
list1 = list1[::-1]
print(list1[K-1])

Submission status: Accepted

Solution code:
A,B,K =map(int,input().split())
list = []
for i in range(1,min(A,B)+1):
    if A % i == 0 and B % i == 0:
        list.append(i)
list.sort(reverse=True)
print(list[K - 1])

Submission status: Accepted

Solution code:
A,B,K =map(int,input().split())
list = []

for i in range(1,101):
    if A % i == 0 and B % i == 0:
        list.append(i)
list.sort(reverse=True)
print(list[K - 1])

Submission status: Accepted

Solution code:
import fractions
a,b,k=map(int,input().split())
n=fractions.gcd(a,b)
l=[]
ld=[]
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        l.append(i)
        ld.append(n//i)
if ld[-1]==l[-1]:del ld[-1]
l+=ld[::-1]
print(l[-k])

Submission status: Accepted

Solution code:
a,b,k = map(int,input().split())
l = []
for i in range(1,101):
    if a%i == 0 and b%i == 0:
        l.append(i)
print(l[::-1][k-1])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())

for i in range(1, min(A, B) + 1)[::-1]:
    if A % i == 0 and B % i == 0:
        K -= 1

    if K == 0:
        print(i)
        break

Submission status: Accepted

Solution code:
A,B, K = map(int,input().split())
m= min(A,B)
count =0
for i in range(m,0,-1):
  if A%i ==0 and B%i==0:
    count +=1
    if count ==K:
      ans=i
      break
print(i)

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
a, b = [], []
for i in range(1,A+1):
    if A % i == 0:
        a.append(i)
for j in range(1,B+1):
    if B % j == 0:
        b.append(j)
lis = [k for k in a if k in b]
lis.reverse()
print(lis[K-1])

Submission status: Accepted

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


A, B, K = list(map(int, input().split()))

# print(A, K)

set_A = set()
set_B = set()

for i in range(1, A + 1):
    if A % i == 0:
        set_A.add(i)


for i in range(1, B + 1):
    if B % i == 0:
        set_B.add(i)

# print(set_A ,set_B)

seki = set_A & set_B

seki = list(seki)

seki.sort(reverse=True)

print(seki[K - 1])

Submission status: Accepted

Solution code:
inn = input().split()
a = int(inn[0])
b = int(inn[1])
k = int(inn[2])

start = max(a, b) + 1
count = 0


rlist = list(range(0, start))
rlist.reverse()
for i in rlist:
    if a % i == 0 and b % i == 0:
        count += 1
        if count == k:
            print(i)
            break

Submission status: Accepted

Solution code:
A,B,K =  map(int,input().split())
C=[]


N = min(A,B)

for i in range(N):
    if A % (i+1) == 0:
        if B % (i+1) ==0:
            C.append(i+1)

N = len(C)
print(int(C[N-K]))

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())

counter = 0
for i in range(100, 0, -1):
    if A % i == 0 and B % i == 0:
        counter += 1
    if counter == K:
        print(i)
        break

Submission status: Accepted

Solution code:

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

divs = []

for i in range(1, min(a,b)+1):
    if a % i == 0 and b % i == 0:
        divs.append(i)

divs.reverse()
print(divs[k-1])

Submission status: Accepted

Solution code:
n = input().split()
A = int(n[0])
B = int(n[1])
K = int(n[2])
yAArr = []
yBArr = []
pubArr = []
# AとBの公約数を調べる
for i in range(1,A):
   if A % i == 0:
       yAArr.append(i)
yAArr.append(A)
for i in range(1,B):
    if B % i == 0:
        yBArr.append(i)
yBArr.append(B)

pubArr = list(set(yAArr) & set(yBArr))
pubArr = sorted(pubArr, reverse=True)

for i, name in enumerate(pubArr):
    if i + 1 == K:
        print(pubArr[i])
        break

Submission status: Accepted

Solution code:
a,b,k = map(int,input().split())
m = min(a,b)
count = 0
for i in range(m,0,-1):
  if i == 0:
    break
  if a%i == 0 and b%i == 0:
    count += 1
  if count == k:
    break
print(i)

Submission status: Accepted

Solution code:
A,B,K=map(int,input().split())
C=min(A,B)
D=[0]*C

for i in range(C):
  if A%(i+1) == 0 and B%(i+1) == 0:
    D[i]=i+1
  else:
    D[i]=0

D=sorted(D,reverse=True)
print(D[K-1])

Submission status: Accepted

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

c = min(a, b)
count = 0
for i in range(c):
    if a % (c-i) == 0 and b % (c-i) == 0:
        count += 1
    if count == k:
        print(c-i)
        break

Submission status: Accepted

Solution code:
A,B,K = map(int, input().split())

n = min(A, B)
count = 0
for i in range(n, 0, -1):
    if i == 0:
        break
    if A%i == 0 and B%i == 0:
        count = count + 1
        if count == K:
            break
print(i)

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())

List = [x for x in range(min(A,B),0,-1) if A%x ==0 and B%x ==0]
print(List[K-1])

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
d = max(a, b)
l = []
for i in range(1,d+1):
  if a % i == 0 and b % i == 0:
    l.append(i)
print(l[len(l)-c])

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
n=[]
for i in range(1,min(a,b)+1):
  if a%i==0 and b%i==0:
    n.append(i)
print(n[-k])

Submission status: Accepted

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

res = []
for i in range(1, 101):
    if (a % i == 0) & (b % i == 0):
        res.append(i)

sorted(res)
print(res[-k])

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
d = max(a, b)
l = []
for i in range(1,d+1):
  if a % i == 0 and b % i == 0:
    l.append(i)
print(l[len(l)-c])

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
max = max(a, b)
ans = []
for i in range(1, max+1):
  if a % i == 0 and b % i == 0:
    ans.append(i)
print(ans[-(k)])

Submission status: Accepted

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


def f(s, l, k):
    numbers = []
    for i in range(1, s + 1):
        if s % i == 0 and l % i == 0:
            numbers.append(i)

    print(numbers[-k])


if a > b:
    f(b, a, k)
else:
    f(a, b, k)

Submission status: Accepted

Solution code:
m = list(map(int, input().split()))
a = m[0]
b = m[1]
k = m[2]
c = min(a, b)
d = 0
e = 0

for i in range(c):
    if(a % (c - i) == 0 and b % (c - i) == 0):
        d += 1
    if(d == k):
        e = c - i
        break
print(e)

Submission status: Accepted

Solution code:
a,b,k = map(int,input().split())
c = []
for i in range(min(a,b)):
    if a%(i+1) == 0 and b%(i+1) == 0:
        c.append(i+1)
print(c[-k])

Submission status: Accepted

Solution code:
import numpy as np
a,b,k = map(int,input().split())
c = np.array(list(range(1,min(a,b)+1))) #a,bのうち小さい方の数字までのリスト
#両方が０のインデックスのリストを返して、後ろからk番目のインデックス番号のcをprint
e = [f for f,g in enumerate(zip(a%c,b%c)) if g == (0,0)]
print(c[e[-k]])

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
n = []

for i in range(1, min(a, b) + 1):
    if a % i == 0 and b % i == 0:
        n += [i]

print(n[-k])

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
divisor = []
for i in range(1, min(a, b)+1):
	if a % i == 0 and b % i == 0:
		divisor.append(i)
divisor.sort(reverse=True)
print(divisor[k-1])

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
ans=[]
for i in range(1,200):
  if a%i==0 and b%i==0:
    ans.append(i)
print(ans[-k])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
counter = 0

for i in reversed(range(0, min(A, B)+1)):
    if A % i == 0 and B % i == 0:
        counter += 1
    if counter == K:
        print(i)
        break

Submission status: Accepted

Solution code:
A,B,K = map(int, input().split())
mylist = []
for i in range(1,max(A,B)+1):
  if A%i == 0 and B%i == 0:
    mylist.append(i)
newlist = sorted(mylist, reverse = True)
print(newlist[K-1])

Submission status: Accepted

Solution code:
A,B,K=map(int,input().split())
tmp=[]
for i in range(1,min(A,B)+1):
    if A%i==0 and B%i==0:
        tmp.append(i)
print(tmp[-K])

Submission status: Accepted

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

for i in range(min(a, b)+1, 0, -1):
    if a % i == 0 and b % i == 0:
        k -= 1
    if k == 0:
        print(i)
        break

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
divide_list = []
for i in range(1,min(A,B) + 1):
  if A%i ==0 and B%i ==0:
    divide_list.append(i)
print(divide_list[-K])

Submission status: Accepted

Solution code:
A,B,K=map(int,input().split())
count=0
i=min(A,B)+1
while count<K:
  i-=1
  if A%i==0 and B%i==0:
    count+=1
print(i)

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
l = []
for i in range(1, 101):
    if A % i == 0 and B % i == 0:
        l.append(i)
l.sort(reverse=True)
print(l[K - 1])

Submission status: Accepted

Solution code:
a, b, k = map(int,input().split())
cnt = k
x = min(a,b)

for i in range(1,x+1)[::-1]:
    if a%i == 0 and b%i == 0:
        cnt -= 1
    if cnt == 0:
        break
print(i)

Submission status: Accepted

Solution code:
import sys

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


stdout_write = sys.stdout.write

for line in sys.stdin:
  a, b, k = (int(i) for i in line.strip().split())
  ans = gcd(a, b)
  while True:
    if (a % ans) == 0 and (b % ans) == 0:
      k -= 1
      if k == 0: break
    ans -= 1

stdout_write('{}\n'.format(ans))

Submission status: Accepted

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
                
    divisors.sort()
    return divisors
 
 
a, b, c = map(int, input().split())
 
c_set = list(set(make_divisors(a))&set(make_divisors(b)))
 
c_set.sort()
print(c_set[-c])

Submission status: Accepted

Solution code:

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


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

c_set = list(set(make_divisors(a))&set(make_divisors(b)))

c_set.sort()
# print(c_set)
print(c_set[-c])

Submission status: Accepted

Solution code:
A,B,K = map(int, input().split())

if A > B:
  C=A
  A=B
  B=C
k = 0
cnt = 0
while True:
  if A % (A-cnt) == 0 and B % (A-cnt) == 0:
    k += 1
    if k == K:
      print(A-cnt)
      break
  cnt += 1

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())

count = 0
for i in range(min(A, B)):
    i = min(A, B) - i
    if A % i == 0 and B % i == 0:
        count += 1
        if count == K:
            print(i)
            break

Submission status: Accepted

Solution code:
a,b,K = map(int,input().split())
cnt,ans = 0,0
for i in range(1,min(a,b)+1)[::-1]:
    if a%i==0 and b%i==0:
        cnt += 1
        if cnt==K:
            print(i)
            break

Submission status: Accepted

Solution code:
list = raw_input().split()

A = int(list[0])

B = int(list[1])

K = int(list[2])

count = 0

for n in range(A, 0 , -1):
    if A % n == 0:
        if B % n == 0:
            count += 1
    if count == K:
        break

print n

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
ab = []

if a >= b:
    i = b
else:
    i = a

while i > 0:
    if a % i == 0 and b % i == 0:
        ab.append(i)
    i -= 1

print(ab[k - 1])

Submission status: Accepted

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

for i in range(max(a,b), 0, -1):
	if a%i == 0 and b%i == 0:
		k -= 1
		if k == 0:
			print(i)
			break

Submission status: Accepted

Solution code:
A,B,K=map(int,input().split())
listAB=[]
for i in range(min(A,B)):
    if A%(i+1)==0 and B%(i+1)==0:
        listAB.append(i+1)
listAB.sort(reverse=1)
if A==1 and B==1:
    print(1)
else :
    print(listAB[K-1])

Submission status: Accepted

Solution code:
A, B, K = map(int,input().split())
listAB = []
for i in range(min(A,B)):
    if A%(i+1) == 0 and B % (i+1) == 0:
        listAB.append(i+1)
listAB.sort(reverse = True)
if A == 1 or B == 1:
    print(1)
else:
    print(listAB[K-1])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())

num_list = [(x+1) for x in range(100) if (A % (x+1) == 0) and (B % (x+1) == 0)]
num_list.sort(reverse = True)
print(num_list[K-1])

Submission status: Accepted

Solution code:
A,B,K=map(int,input().split())
a=0
C=[]
for i in range(1,min(A,B)+1):
    if A%i==0 and B%i==0:
        C.append(i)
print(C[-K])

Submission status: Accepted

Solution code:
a,b,n=map(int,input().split())
c=[]
i=0
while(1):
  i=i+1
  if a%i==0 and b%i==0:
    c.append(i)
  if a<=i or b<=i:
    break
d=len(c)-n
print(c[d])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, K: int):
    div = []
    for i in range(1,min(A,B)+1):
        if A % i == 0 and B % i == 0:
            div.append(i)
    print(div[len(div) - K])
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,k = map(int, input().split())
count = 0
for i in range (min(a,b),0,-1):
	if a % i == 0 and b % i == 0:
		count += 1
		d = i;
	if count == k:
		print(d)
		break

Submission status: Accepted

Solution code:
def solve(a, b, k):
    num = 0
    for i in range(100, 0, -1):
        if a % i == 0 and b % i == 0:
            num += 1
        if num == k:
            return i


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

    ans = solve(a, b, k)
    print(ans)


main()

Submission status: Accepted

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

A, B, K = map(int, raw_input().split())

g = gcd(A, B)
cnt = 1

while cnt != K:
	g -= 1
	if A % g == 0 and B % g == 0:
		cnt += 1

print g

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
print([x for x in range(1, min(a,b)+1) if a%x == b%x == 0][-k])

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())

cnt = 0
d = 0
for i in range(min(A,B),0,-1):
    if A % i == 0 and B % i == 0:
        cnt += 1
        d = i
    if cnt == K:
        print(d)
        break

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
G = 0
while A % B != 0:
	A, B = B, A % B
else:
	G = B
list = []
for i in range(1, G + 1, 1):
	if G % i == 0:
		list.append(i)
print(G // list[K - 1])

Submission status: Accepted

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

c = []
for i in range(1, a + 1):
    if a % i == 0 and b % i == 0:
        c.insert(0,i)

print(c[k-1])

Submission status: Accepted

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

l = [1]
for i in range(2, min(a, b) + 1, 1):
  if a % i == 0 and b % i == 0:
    l.append(i)

print(l[-k])

Submission status: Accepted

Solution code:
A,B,K=[int(i) for i in input().split()]
a=[]
for i in range(1,max(A,B)+1):
  if A%i==0 and B%i==0:
    a.append(i)
print(a[-K])

Submission status: Accepted

Solution code:
import sys

A, B, K = map(int, input().split())
ans = 0
count = 0

for i in range(100):
    if A % (100 - i) == 0 and B % (100 - i) == 0:
        ans = 100 - i
        count += 1
        if count == K:
            print(ans)
            sys.exit()

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
m=max(a,b)
ans=[]
for i in range(1,m+1):
  if a%i==0 and b%i==0:
    ans.append(i)
ans.reverse()
print(ans[k-1])

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
list = []
for i in range(max([A,B])+1):
    if i != 0 and A % i == 0 and B % i == 0:
        list.append(i)

list.sort(reverse = True)
if len(list) == 1:
    print(list[0])
else:
    print(list[K-1])

Submission status: Accepted

Solution code:
A,B,K = map(int, input().split())
count = 0
for i in list(range(A))[::-1]:
  i += 1
  if (not (A%i)) and (not (B%i)):
    count += 1
    if count == K:
      print(i)

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
ya = []
for i in range(1, 101):
    if a % i == 0 and b % i == 0:
        ya.append(i)
print(ya[-k])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())

for i in range(max(A,B), 0, -1):
    if A % i == 0 and B % i == 0:
        K -= 1
    if K == 0:
        print(i)
        break

Submission status: Accepted

Solution code:
a,b,k = map(int,input().split())
tmp = 0
for i in reversed(range(1,101)):
  if a % i == 0 and b % i == 0:
    k -= 1
    tmp = i
  if k == 0:
    break
print(tmp)

Submission status: Accepted

Solution code:
A, B, K = map(int,input().split())

a = [i for i in range(1, A+1) if A % i == 0]
b = [i for i in range(1, B+1) if B % i == 0]
ans = set(a) & set(b)
print(sorted(list(ans))[-K])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())

l = [i for i in range(1, 101) if (A % i == 0 and B % i == 0)]
l = l[::-1]

print(l[K-1])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())

c_d = []
for i in range(1, 101):
    if A % i == 0 and B % i == 0:
        c_d.append(i)

c_d.sort(reverse=True)

print(c_d[K-1])

Submission status: Accepted

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

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

    divisors.sort()
    return divisors

ab = list(set(make_divisors(a)) & set(make_divisors(b)))
ab.sort()
print ab[len(ab)-k]

Submission status: Accepted

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

l=[]

for i in range(1,101):
    if a%i == 0 and b%i ==0:
        l.append(i)

l.sort(reverse=True)

print(l[k-1])

Submission status: Accepted

Solution code:
A, B, K = list(map(int, input().split(' ')))
candidate = [1]
for i in range(2, min(A, B) + 1):
    if A % i == 0 and B % i == 0:
        candidate.append(i)
print(sorted(candidate, reverse=True)[K-1])

Submission status: Accepted

Solution code:
abk = list(map(int,input().split()))
a=abk[0]
b=abk[1]
k=abk[2]
ans=[]
for i in range(1,101):
    if a%i == 0 and b%i ==0:
        ans.append(i)
ansr=list(reversed(ans))
print(ansr[k-1])

Submission status: Accepted

Solution code:
import sys
A, B, K = (int(x) for x in input().split())
N = min([A, B]) + 1
counter, ans = 0, 1
for x in range(1, N):
    x = N - x
    if A % x == 0 and B % x == 0:
        ans = x
        counter += 1
    if counter == K:
        print(ans)
        sys.exit()