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:
A = list(map(int,input().split( )))
a=A[0]
b=A[1]
k=A[2]
x=0
for h in range(100):
	i= (b if a>b else a)-h
	if a%i + b%i:
		continue
	x=x+1
	if x == k:
		break
print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, k = map(int, 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:
A,B,K = [int(_) for _ in input().split()]
c = 0
i = 100
while True:
    if A%i == B%i == 0:
        c += 1
    if c == K:
        break
    i -= 1
print(i)

Submission status: Accepted

Solution code:
import math
A,B,C=map(int,input().split())
res=0
for i in range(100):
  if A%(100-i)==0 and B%(100-i)==0:
      res+=1
      if res==C:
        print(100-i)

Submission status: Accepted

Solution code:
a,b,k = [int(s) for s in input().rstrip().split()]
j=0
for i in range(min(a,b),0,-1):
    if (a%i == 0) and (b%i == 0):
        j+=1
        if j == k:
            break

print(i)

Submission status: Accepted

Solution code:
from sys import stdin

a = [int(i) for i in stdin.readline().rstrip().split(' ')]

min = min([a[0], a[1]])
max = max([a[0], a[1]])

k = 0
for i in list(reversed(range(1, min + 1))):
    if max % i == 0 and min % i == 0:
        k += 1
        if k == a[2]:
            print(i)
            break

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split(" "))
flag = True
counter = 0
i = max(A, B)
while True:
  if A % i == 0 and B % i == 0:
    counter += 1
    if counter == K:
      print(i)
      break
  i -= 1

Submission status: Accepted

Solution code:
# coding: utf-8
a, b, k = map(int, input().split())

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

Submission status: Accepted

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

rtn = max(A, B); 
rtn_list =[] 
while len(rtn_list) < K:
    if not(A % rtn) and not(B % rtn):
        rtn_list.append(rtn)
    rtn -= 1
print(rtn_list[-1])

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
list = []
list1 = []
for i in range(a):
  d = a % (i+1)
  if d == 0:
    list.append(i+1)
  else:
    pass
for k in range(len(list)):
  e = b % list[k]
  if e == 0:
    list1.append(list[k])
  else:
    pass
print(list1[-c])

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
num1 = a[0]
num2 = a[1]
list1 = []
list2 = []
max = a[2]
for i in range(1, num1 + 1):
  if num1 % i == 0:
    list1.append(i)
    
for i in range(1, num2 + 1):
  if num2 % i == 0:
    list2.append(i)

list3 = list(set(list1) & set(list2))
list3.sort()
list3.reverse()

print(list3[max -1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

def cd(a,k):
    for i in reversed(range(1,a+1)):
        if a%i == 0:
            k = k-1
            if k==0:
                return i
    return -1

print(cd(gcd(a,b),k))

Submission status: Accepted

Solution code:
import sys

i = list(map(int, input().split()))
A = i[0]
B = i[1]
K = i[2]

yaku_A = []
yaku_B = []

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

for i in range(1,B+1):
    if B % i == 0:
        yaku_B.append(i)
        
SS = list(set(yaku_A) & set(yaku_B))
SSS = sorted(SS)
        
print(SSS[-K])

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
for i in range(100,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, c = map(int, input().split(' '))
lists = []
for i in range(1, min(a, b) + 1):
  if a % i == 0 and b % i == 0:
    lists.append(i)
print (lists[len(lists) - c])

Submission status: Accepted

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

Submission status: Accepted

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

A = inp[0]
B = inp[1]
K = inp[2]

# 約数を求める
yakusuu_a = []
yakusuu_b = []

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

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

c = []
for i in yakusuu_a:
  if i in yakusuu_b:
    c.append(i)

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

Submission status: Accepted

Solution code:
import fractions
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass #sortされていない
a,b,k = map(int,input().split())
gcd = fractions.gcd(a,b)
yaku = list(reversed(sorted(list(set(divisor(gcd))))))
print(yaku[k-1])

Submission status: Accepted

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

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

GCA = gcd(A, B)
A_all_div=[]
B_all_div=[]


for i in range(1,A+1):
    if A % i == 0:
        if i <= GCA:
            A_all_div.append(i)
A_all_div.sort(reverse=True)

for i in range(1,B+1):
    if B % i == 0:
        if i <= GCA:
            B_all_div.append(i)
B_all_div.sort(reverse=True)

ALL_DIV = set(A_all_div) & set(B_all_div)
all_div = list(ALL_DIV)

all_div.sort(reverse=True)

print(all_div[K-1])

Submission status: Accepted

Solution code:
a, b, k = [int(x) for x in input().split()]
al = set()
bl = set()
for i in range(1, a+1):
    if a%i == 0:
        al.add(i)
for i in range(1, b+1):
    if b%i == 0:
        bl.add(i)
kk = list(al & bl)
kk.sort(reverse=True)
print(kk[k-1])

Submission status: Accepted

Solution code:

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


c=0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
num = max(a, b)
b = min(a, b)
a = num
while 1:
    num = a % b
    if num == 0:
        break
    a = b
    b = num
num = 0
for i in range(1, b+1):
    if b % i == 0:
        num += 1

    if num == k:
        print(b//i)
        break

Submission status: Accepted

Solution code:
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
A,B,K=map(int,input().split())
G=gcd(A,B)
L=[]
for i in range(1,G+1):
    if G%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())

ans = 0

lista = list(range(a+1))
aa = lista.pop(0)

listb = list(range(b+1))
bb = listb.pop(0)

if (a < b):
    li = [i for i in lista if a % i == 0 and b % i == 0]
    li = sorted(li, reverse=True)
    ans = li[k-1]
else:
    li = [i for i in listb if a % i == 0 and b % i == 0]
    li = sorted(li, reverse=True)
    ans = li[k-1]

print(ans)

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[len(l)-k])

Submission status: Accepted

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

Submission status: Accepted

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

a=int(c[0])
b=int(c[1])
c=int(c[2])
num = [1]
#print(num)
d = a
if a>b:
    d = b
i=int(2)
while i <= d:
    if a%i==0  and b%i==0:
        num.append(i)
        i += 1
    else:
        i += 1

#print(num)
print(num[len(num)-c])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
i = 0
j = 100
ans = 1
while (i < K):
    if (A % j == 0) & (B % j == 0):
        ans = j
        i += 1
    j -= 1

print(int(ans))

Submission status: Accepted

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

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

print(List[-k])

Submission status: Accepted

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

a,b,k=[int(s)for s in input().split()]
g=euclid(a,b) if a>b else euclid(b,a)
d=[]
for i in range(g):
  if g%(i+1)==0:d.append(i+1)

print(d[-k])

Submission status: Accepted

Solution code:
def get_div(num):
    if num == 1:
        return [1]
    else:
        return [i for i in range(1,num+1) if num%i==0]

A, B, K  = [int(a) for a in input().split()]
cat = get_div(A) + get_div(B)
dup = sorted([x for x in set(cat) if cat.count(x) > 1])
dup.reverse()
print(dup[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split(' '))
A_set = set()
B_set = set()
for number in range(1, A+1):
    if A%number == 0:
        A_set.add(number)

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

A_Bset = A_set & B_set
A_Blist = list(A_Bset)
A_Blist.sort(reverse=True)
print(A_Blist[K-1])

Submission status: Accepted

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

print(divisor[-k])

Submission status: Accepted

Solution code:
import sys
A,B,K=[int(i) for i in input().split(" ")]
count=0
for i in range(101,0,-1):
    if A%i==0 and B%i==0:
        count+=1
    if count==K:
        print(i)
        sys.exit()

Submission status: Accepted

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

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

Submission status: Accepted

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

hoge = []
m = min(A, B)

for i in range(1, m + 1):
    if A % i == 0 and A // i > 0 and B % i == 0 and B // i > 0:
        hoge.append(i)
        
fuga = sorted(list(set(hoge)))
a = len(fuga) - K
print(fuga[a])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
count = 0
for i in range(100, 0, -1):
  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 = 0
arr=list(range(1,max(a,b)+1))
arr.reverse()
for x in arr:
  if (a % x == 0) and (b % x == 0):
    cnt +=1
    if cnt == k:
      print (x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
n = 1
count = 0
list = []
while n <= a and n <=  b:
    if a % n == 0 and b % n == 0:
        list.append(n)
        n += 1
    else:
        n += 1
print(list[-k])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import queue
a,b,c = map(int,input().split())
q = queue.LifoQueue()
for i in range(1,101):
  if(a%i == 0 and b%i == 0):
    q.put(i)
for i in range(c-1):
  q.get()
print(q.get())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a, b, k = map(int, input().split())
m = max(a,b)
al = [i for i in range(1,m+1) if a%i==0]
bl = [i for i in range(1,m+1) if b%i==0]
ans = sorted(list(set(al)&set(bl)))[::-1]
print(ans[k-1])

Submission status: Accepted

Solution code:
import math
A,B ,K= map(int,input().split(" "))
def gcd (a: int,b: int) -> int:
    if a < b: a,b = b,a
    return a if b == 0 else gcd(b,a%b)
def lcm (a: int,b: int) -> int:
    return a // gcd(a,b) * b

g = gcd(A,B)

itermx = math.sqrt(g)+1
lst = []
for j in range(1,int(itermx+1)):
    if g % j == 0:
        lst.append(j)
        if g // j != j:
            lst.append(g//j)
lst.sort(reverse=True)
print(lst[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
import copy

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

ab_gcd = fractions.gcd(A, B)
if ab_gcd == 1:
    print(ab_gcd)
    quit()

p = 2
elem = []
while p * p <= ab_gcd:
    while ab_gcd % p == 0:
        ab_gcd //= p
        elem.append(p)
    p = p + 1

if ab_gcd > 1:
    elem.append(ab_gcd)

cds = []
for c in elem:
    for i in range(2):
        e = c ** i
        if cds:
            copy_cds = copy.deepcopy(cds)
            for cd in copy_cds:
                cds.append(cd*e)
        cds.append(e)

cds = list(set(cds))
cds.sort(reverse=True)
print(cds[K-1])

Submission status: Accepted

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

list=[]
for j in range(1,101):
	a,b = A,B
	if a%j==0 and b%j==0:
		a,b = a/j, b/j
		list.append(j)

print(list[-K])

Submission status: Accepted

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

Submission status: Accepted

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

def lcm(x,y):
    if y==0:
        return x
    else:
        return lcm(y,x%y)
yaku=[]
mx=lcm(x,y)
for i in range(1,mx):
    if mx%i==0:
        yaku.append(i)
yaku.append(mx)
print(yaku[-k])

Submission status: Accepted

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

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

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

koyakusu = list(set(yakusu_a) & set(yakusu_b))
koyakusu_sort = sorted(koyakusu,reverse=True)
print(koyakusu_sort[K-1])
#print(koyakusu_sort)
#print(yakusu_a)
#print(yakusu_b)

Submission status: Accepted

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

A_list=list()
B_list=list()
C_list=list()

for i in range(A+1):
    if i==0:
        continue
    if A%i==0:
        A_list.append(i)

for x in range(B+1):
    if x==0:
        continue
    if B%x==0:
        B_list.append(x)

for y in A_list:
    for z in B_list:
        if y==z:
            C_list.append(y)



print(C_list[-K])

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math

import array
import bisect
import collections
from collections import Counter, defaultdict
import fractions
import heapq
import re

sys.setrecursionlimit(1000000)


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

def argsort(l, reverse=False):
    return sorted(range(len(l)), key=lambda i: l[i], reverse=reverse)

def argmin(l):
    return l.index(min(l))

def YESNO(ans, yes="YES", no="NO"):
    print([no, yes][ans])

II = lambda: int(input())
MI = lambda: map(int, input().split())
MIL = lambda: list(MI())
MIS = lambda: input().split()


def main():
    a, b, k = MI()
    for i in range(max(a, b), 0, -1):
        k -= (a % i == 0) and (b % i == 0)
        if k == 0:
            return i


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

    num = []

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

    print(num[-k])

if __name__ == "__main__":
    main()

Submission status: Accepted

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

    #print(max_gcd)
    #print(yakusuu_array)
    print(yakusuu_array[-(k-1)])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
k = 0
max_val = min(A,B) + 1
L = list(reversed((range(1, min(A,B) + 1))))

for div in L:
	if A%div == 0 and B%div == 0:
		k = k + 1
		if k == K:
			print(div)
			exit()

Submission status: Accepted

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

def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

list_A = make_divisor_list(A)
list_B = make_divisor_list(B)

list_and = set(list_A) & set(list_B)

list_and_sort = sorted(list_and, reverse=True)

print(list_and_sort[K-1])

Submission status: Accepted

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

a,b,c= map(int, input().split())
d= int(gcd(a,b))
if c==1:
  print(d)
else:
  arr=[]
  for i in range(1,d):
    if(d%i == 0):
      arr.append(i)
  print(arr[-(c-1)])

Submission status: Accepted

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

array1 = []
array2 = []

array1 = [i for i in range(1, a+1) if a % i == 0]
array2 = [i for i in range(1, b+1) if b % i == 0]

array = list(set(array1) & set(array2))
array.sort()
print(array[-k])

Submission status: Accepted

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

yakusuu=[]
yakusuuA = []
yakusuuB = []
for i in range(1,A+1):
  if A% i == 0:
    yakusuuA.append(i)
  
for j in range(1,B+1):
  if B%j == 0:
    yakusuuB.append(j)
    
yakusuu = list(set(yakusuuA) & set(yakusuuB))
yakusuu.append(1)     
print(sorted(yakusuu, reverse=True)[K-1])

Submission status: Accepted

Solution code:
#-*- coding: utf-8 -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math



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

def sol(a, b, k):
    D = []
    for i in range(1, min(a, b)+1):
        if a % i == 0 and b % i == 0:
            D.append(i)
    D.reverse()
    return D[k-1]



do_submit = True
#do_submit = False
def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(int, line.split())) for line in lines]
    a, b, c = parsed_lines[0]
    return a, b, c


if not do_submit:
    a, b, c = input_parse("""
    8 12 2
    """)
    print(sol(a, b, c))
    a, b, c = input_parse("""
    100 50 4
    """)
    print(sol(a, b, c))
    a, b, c = input_parse("""
    1 1 1
    """)
    print(sol(a, b, c))
else:
    a, b, k = list(map(int, input().split()))
    print(sol(a, b, k))
    # S = []
    # for i in len(n):
    #     S.append(int(input().strip()))
    #print(sol(n, a, b, c, S))

Submission status: Accepted

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

a,b,k=map(int,input().split())
l=[]
g=gcd(a,b)

if a==1 and b==1:
  print(1)
else:
  for i in range(1,g):
    if g%i==0:
      l.append(i)
  l.append(g)
  print(l[(-1)*k])

Submission status: Accepted

Solution code:
def hcf(x, y):
    if x > y:
       smaller = y
    else:
       smaller = x
    for i in range(1,smaller + 1):
       if((x % i == 0) and (y % i == 0)):
           hcf = i
    return hcf

n = input().split()
a = hcf(int(n[0]), int(n[1]))
c = 0
d = a
for i in range(a):
  if (a%d) == 0:
    c = c + 1
  if c == int(n[2]):
    print(d)
    break
  d = d - 1

Submission status: Accepted

Solution code:
import sys
A, B, K = [int(x) for x in sys.stdin.readline().rstrip().split()]
cur = min(A, B) + 1
while K > 0:
    cur -= 1
    if not (A % cur == 0 and B % cur == 0):
        continue
    K -= 1
print(cur)

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:
import fractions

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

n = fractions.gcd(a, b)

l = []
for i in range(1, n + 1):
    if n % i == 0:
        l.append(i)

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

Submission status: Accepted

Solution code:
def gcd(a, b):
  if a < b:   
  	a, b = b, a
  y = a % b
  if y == 0:
  	return b
  else:
  	a, b = b, y
  	return gcd(a,b)
x = [int(i) for i in input().split()]
fac = []
fac.append(1)
i = gcd(x[0], x[1])
for j in range(2, i + 1):
  if (i % j == 0):
    fac.append(j)
print(fac[::-1][x[2]-1])

Submission status: Accepted

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

e = []
for i in range(1,b+1):
    if b%i == 0:
        e.append(i)

f = set(d) & set(e)
f = list(f)
f = sorted(f,reverse=True)

print(f[c-1])

Submission status: Accepted

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

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:
a,b,k=map(int,input().split());i=a;r=0
while True:
  if a%i==0and b%i==0:r+=1
  if k==r:break
  i-=1
print(i)

Submission status: Accepted

Solution code:
a,b,c = map(int, input().split())
def m(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list


list = m(a)+ m(b)
res = [e for e in set(list) if list.count(e) > 1]
res.sort(reverse=True)
print(res[c-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
k = 0
x = 1
l = [0]


for x in range(min([A, B])+1):
    if x != 0:
        if (A % x == 0) & (B % x == 0):
            l.append(x)
l.reverse()

print(l[K-1])

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)
ans.sort(reverse=True)
print(ans[K-1])

Submission status: Accepted

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

ans = []
for n in range(1,101):
    if A%n==0 and B%n==0:
        ans.append(n)
print(ans[-K])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/3
Solved on 2019/3/3
@author: shinjisu
"""


# ABC 120
# import math


def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**12


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def prob_B():
    A, B, K = getIntList()
    dmp((A, B, K))
    count = 0
    i = 100
    while count < K:
        if A % i == 0 and B % i ==0:
            count += 1
            if count == K:
                break
        i -= 1
    return i


def prob_C():
    S = input()
    red = 0
    blue = 0
    for cube in S:
        if cube == '0':
            red += 1
        else:
            blue += 1
    dmp((red, blue))
    return min(red, blue)*2


def prob_D():
    N, M = getIntList()
    dmp((N, M))
    A = zeros(M)
    B = zeros(M)
    for i in range(M):
        A[i], B[i] = getIntList()
    dmp(A, 'A')
    dmp(B, 'B')
    return 123


debug = False  # True False
ans = prob_B()
print(ans)
#for row in ans:
#    print(row)


def prob_A():
    A, B, C = getIntList()
    dmp((A, B, C))
    count = min(B // A, C)
    return count

Submission status: Accepted

Solution code:
import sys

data= sys.stdin.readline().split(" ")
a = int(data[0])
b = int(data[1])
k = int(data[2])

if a == 1 or b == 1:
    print(a)

else:
    t = a
    if a < b:
        t = b
    t += 1
    count = 0
    for i in reversed(range(1, t)):
        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())
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())

def ooo(x):
    lix =[]
    for i in range(1, x+1):
        if x % i == 0:
            lix.append(i)
    return lix

lia = ooo(a)
lib = ooo(b)
li = lia + lib

li2 =[]
for n in range(len(li)):
    if not li[n] in li2: 
        if li.count(li[n]) == 2:
            li2.append(li[n])

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def euclidean(a,b):
    if a < b:
        tmp = a
        a = b
        b = tmp
    if a%b != 0:
        return euclidean(a%b, b)
    else:
        return b

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,k=list(map(int,input().split()))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
num=gcd(a,b)
c=[]
for i in range(1,num+1):
    if num % i == 0:
        c.append(i)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, k = input().split()
a = int(a)
b = int(b)
k = int(k)
a_list = []
b_list = []
for j in range(a):
    i = j + 1
    if a % i == 0:
        a_list.append(i)
for j in range(b):
    i = j + 1
    if b % i == 0:
        b_list.append(i)

#a_list.extend(b_list)
#co_divisor = list(set(a_list))
a_list = set(a_list)
b_list = set(b_list)
co_divisor = list(a_list & b_list)
co_divisor.sort(reverse=True)
print(co_divisor[k-1])

Submission status: Accepted

Solution code:
a, b, k = list(map(int, input().split()))
# 公約数を入れておくリスト
common_divisor = []

# 1もカウントするので、少ない方の数まで1から数え上げる
# 数え上げて、いずれもその数であまりが0であれば公約数である
for i in range(1,min(a,b)+1):
    if a % i == 0 and b % i == 0:
        common_divisor.append(i)

# 公約数のうち、指定された番号の数を出力する。indexは0スタートなので-1してあわせる
copy_common_divisor = list(reversed(common_divisor))
print(copy_common_divisor[k - 1])

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

a, b, c = map(int, input().split())
cnt = 0
for i in reversed(range(1, 101)):
    if a % i == 0 and b % i == 0:
        cnt += 1
    if cnt == c:
        break
print(i)

Submission status: Accepted

Solution code:
tmp = [int(i) for i in raw_input().split()]
list1 = []
list2 = []
for i in range(100):

    amari = tmp[0]%(i+1)

    if amari == 0:
        list1.append(i+1)

for i in range(100):
    amari = tmp[1] % (i+1)

    if amari == 0:
        list2.append(i+1)

match = []

for i in list1:
    for s in list2:
        if i == s:
            match.append(s)

print(match[len(match)-tmp[2]])

Submission status: Accepted

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

Submission status: Accepted

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

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

warikiru.reverse()
print(warikiru[K-1])