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

Solution (Python):
import fractions

ABK = list(map(int,input().split()))
LCM = ABK[0] * ABK[1] // fractions.gcd(ABK[0],ABK[1])
count = 0

while count < ABK[2]:
    if ABK[0] % LCM == 0:
        if ABK[1] % LCM == 0:
            count = count + 1
    if count != ABK[2]:
        LCM = LCM - 1

print(LCM)

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

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

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

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

print(ans[k-1])

Solution (Python):
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[len(ans)-k])

Solution (Python):
a,b,k= map(int, input().split())
i=min(a,b)
j=0
while j!=k :
    if a%i==0 and b%i==0:
      j+=1
      if j==k:
        print(i)
        exit()
    i-=1

Solution (Python):
A, B, K = map(int, input().split())
N = min(A, B)
list_gcd = [] 

for i in range(1, N+1):
  if A % i == 0 and B % i == 0:
    list_gcd.append(i)
    
if N == 1:
  Y = max(A,B)
  if Y == 1:
    list_gcd.append(1)
  else:
    for i in range(1, Y):
      if Y % i == 0:
        list_gcd.append(i)

print(list_gcd[-K])

Solution (Python):
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])

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

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

Solution (Python):
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = set(table)
    return table


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

elm = sorted(list(divisor(a) & divisor(b)), reverse = True)
print(elm[c-1])

Solution (Python):

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

print(ptn[-K])

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

Solution (Python):
import fractions

a, b, k = map(int, input().split())
gcd = fractions.gcd(a, b)
divisor = []
for i in range(int(gcd ** 0.5)):
    if gcd % (i + 1) == 0:
        divisor.append(i + 1)
        if gcd // (i + 1) != i + 1:
            divisor.append(gcd // (i + 1))
divisor.sort(reverse = True)
print(divisor[k - 1])

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

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

Solution (Python):
A,B,K = list(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)

l.sort(reverse=True)

print(l[K-1])

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

Solution (Python):
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)
        exit()

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

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

ans = []

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

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

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

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

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

Solution (Python):
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)
    return divisors
a = make_divisors(A)
b = make_divisors(B)
c = sorted(set(a)&set(b))
print(list(c)[-K])

Solution (Python):
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

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

i = min(A, B)
while K != 0:
    if A % i == 0 and B % i == 0:
        K -= 1
    i -= 1

i += 1
print(i)

Solution (Python):
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)

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

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

  if count==K:
    print(i)
    break

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

cnt = 0
s = a

while True:
    if a%s == 0 and b%s == 0:
        cnt += 1
        if cnt == k:
            print(s)
            exit()
    s -= 1

Solution (Python):
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)

    
    return divisors
ali = set(make_divisors(a))
bli = set(make_divisors(b))
li = sorted(list(ali & bli))
print(li[-k])

Solution (Python):

a, b, k = (int(_) for _ in input().split())
num = []
if a > b:
    for i in range(1, a + 1):
        if a % i == 0 and b % i == 0:
            num.append(i)
else:
    for i in range(1, b + 1):
        if a % i == 0 and b % i == 0:
            num.append(i)
if a == 1 and b == 1:
    num.append(1)
print(num[-k])

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

num_list = []

if a > b:
    for i in range(b, 0, -1):
        if a % i == 0 and b % i == 0:
            num_list.append(i)

else:
    for i in range(a, 0, -1):
        if a % i == 0 and b % i == 0:
            num_list.append(i)

print(num_list[c-1])

Solution (Python):
import sys

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)
if l == []:
    print(1)
    sys.exit()
l.sort(reverse=True)
print(l[k-1])

Solution (Python):
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)

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

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

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

def koyaku(x):
    i = 1
    koyaku_list = []
    while i * i <= x:
        if x % i == 0:
            koyaku_list.append(i)
            koyaku_list.append(x // i)
        i += 1
    return list(set(koyaku_list))

a_koyaku = koyaku(a)
b_koyaku = koyaku(b)

common_koyaku = set(a_koyaku).intersection(set(b_koyaku))
ans = sorted(common_koyaku, reverse=True)[k-1]

print(ans)

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

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

print(diflist[-K])

Solution (Python):
S = input()

S = S.split()

S = list(map(int, S))

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

list = []

if A >= B:
  C = B
else:
  C = A

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

print(list[len(list)-K])

Solution (Python):
import math
import sys
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)
    sys.exit()

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

Solution (Python):
A,B,K = map(int,input().split())
cnt=0

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

Solution (Python):

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

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

print(d[-k])

Solution (Python):
from fractions import*
a,b,k=map(int,input().split());c=0
for i in range(a,0,-1):
  if not gcd(a,b)%i:
    c+=1
    if c==k:print(i)

Solution (Python):
from fractions import*
a,b,k=map(int,input().split());s=[]
for i in range(1,a+1):
  if not gcd(a,b)%i:
    s+=[i]
s.sort(reverse=True)
print(s[k-1])

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

def listing(numb):
    temp = []
    for i in range(1, numb+1):
        if numb % i == 0:
            temp.append(i)
    return temp

alist = listing(a)
blist = listing(b)

alist.sort(reverse=True)
blist.sort(reverse=True)
counter = 0

for i in alist:
    if i in blist:
        counter += 1
        if counter == k:
            print(i)
            break

Solution (Python):
"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    A,B,K= map(int, sys.stdin.readline().split())
    l = []
    for i in range(1,min(A,B)+1):
        if A % i ==0 and B%i ==0:
            l.append(i)
    l.reverse()
    print(l[K-1])

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

if(a >= b):
  div = b
else:
  div = a

cnt = 0

for i in range(div):
  res_a = a % (div - i)
  res_b = b % (div - i)

  if ((res_a == 0) & (res_b == 0)):
    cnt += 1
    if(cnt == k):
      print (div - i)
      break

Solution (Python):
A, B, K = list(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])

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

cnt=0
for i in range(100,0,-1):
	if x%i==0 and y%i==0:
		cnt+=1
		if cnt==n:
			print(i)
			break

Solution (Python):
def factor(num):
    factor_set = set()
    for i in range(1,num+1):
        if num%i == 0:
            factor_set.add(i)
    return factor_set

l = [int(i) for i in input().split(" ")]
a = l[0]
b = l[1]
k = l[2]

and_list = sorted(list(factor(a) & factor(b)),reverse=True)
print(and_list[k-1])

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

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

Solution (Python):
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])

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

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

Solution (Python):
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

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

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

def main():
    A, B, K = i2nn()
    g = gcd(A, B)
    dd = divisors(g)
    dd.sort()
    dd.reverse()
    n = dd[K-1]
    print(n)

main()

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

print(ans[-K])

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

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

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

print(l_cd[-k])

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

Solution (Python):
A, B, K = map(int, input().split())
L = [1]

for i in range(2, 101):
    if A % i == 0 and B % i == 0:
        L.append(i)

print(L[-K])

Solution (Python):
def common_divisor(a, b):
    cd_list = []
    for i in range(1, 101):
        if a % i == 0 and b % i == 0:
            cd_list.append(i)
    return cd_list

A, B, K = map(int, input().split())
print(common_divisor(A, B)[-K])

Solution (Python):
from fractions import gcd


A, B, K = map(int, input().split())
gcd_ = gcd(A, B)
now = 0
for i in range(gcd_, 0, -1):
    if gcd_ % i == 0:
        now += 1
        if now == K:
            print(i)
            exit()

Solution (Python):
A, B, K = map(int, input().split())
index = 0
for i in range(100, 0, -1):
  if A % i == 0 and B % i == 0:
    index += 1
    if(K == index):
      print(i)

Solution (Python):
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[-k])

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

Solution (Python):
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)

Solution (Python):
a,b,k = map(int,input().split())
i = min(a,b)
j = 0
while j < k:
    if a % i == 0:
        if b % i == 0:
            j += 1
    if j == k:
        print(i)
    i -= 1

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

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

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

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

Solution (Python):



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

def d(n):
    div = []
    for i in range(1,n+1):
        if(n % i == 0):
            div.append(i)
    return div
        
a_d = d(a)
b_d = d(b)
s = []
l = []
ab = []

if len(a_d) < len(b_d):
    s = a_d
    l = b_d
else:
    s = b_d
    l = a_d

for i in s:
    if i in l:
        ab.append(i)
print(ab[len(ab)-k])

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

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

cnt = 0

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

    if cnt == k:
        break

print(i)

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

cnt = 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)
      exit()

Solution (Python):
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])

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

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

print(divisor[-k])

Solution (Python):
import fractions
a , b , k= map(int, input().split())


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

print(li[-k])

Solution (Python):
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)

print(divisor[-K])

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

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

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

Solution (Python):
def main():

    """ convenient functions
    
    
    
    
    
    """

    """convenient decorator
    
    
        
        
        
        
        
        
        
        
        
        
    """
    
    
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product 
    
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  
        b, e = 2, 0  
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict 
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
    from copy import deepcopy, copy 
    import operator
    from operator import itemgetter
    
    
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd 
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    
    
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) 
    def modinv(a, p = MOD):
        
        
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        
        
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    """ initialize variables and set inputs
    
        
        
    
        
        
        
        
        
    
        
        
        
        
    
        
        
    """

    
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    
    
    
    
    
    
    
    """

    if __name__ != '__main__':
        
        sys.stdin = open('sample.txt')

    
    

    A, B, K = R()
    count = 0
    for i in range(min(A, B), 0, -1):
        if A % i == 0 and B % i == 0:
            count += 1
        if count == K:
            print(i)
            exit()
    
    print('too bad!')
    
    
    

    """memo: how to use defaultdict of list
    
    Dic = defaultdict(list)
    
    Dic[x].append(y)
    
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()

Solution (Python):
import math


def divisor(div, N):
    
    i = 1
    n = N

    while i <= math.sqrt(n):
        if n % i == 0:
            div.add(i)
            div.add(n // i)
        i += 1


A, B, K = map(int, input().split())
a = set()
b = set()
divisor(a, A)
divisor(b, B)

print(sorted(list(a & b), reverse=True)[K - 1])

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

Solution (Python):
import numpy as np

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

Solution (Python):
a, b, k = map(int, input().split())
tmp = 0
for i in range(max(a, b), 0, -1):
    if(a%i == 0)and(b%i == 0):
        tmp += 1
    if tmp == k:
        print(i)
        exit()

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [A, B, K] = string_to_int(inputs[0])
    results = []
    small = A if A > B else B
    for i in reversed(range(1, small+1)):
        if A % i == 0 and B % i == 0:
            results.append(i)
    return results[K-1]


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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

L = []
for i in range(max(a,b), 0, -1):
    if a%i==0 and b%i==0:
            L.append(i)

print(L[k-1])

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

Solution (Python):
[a,b,k]=map(int,input().split())
res=[i for i in range(1,max(a,b)+1) if a%i==0 and b%i==0]
print(sorted(res,reverse=True)[k-1])

Solution (Python):
[a,b,k]=map(int,input().split())
a_set=set([])
b_set=set([])
for i in range(1,101):
    if a%i == 0:
        a_set.add(i)
for i in range(1,101):
    if b%i ==0:
        b_set.add(i)
res=a_set&b_set
res=list(res)
res.sort(reverse=True)
print(res[k-1])

Solution (Python):
a, b, c = map(int, input().split())
d = 0
for i in range(max(a, b), 0 , -1):
    if a % i == 0 and b % i == 0:
        d += 1
    if d == c:
        print(i)
        exit()

Solution (Python):
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = set(table)
    return table

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

    divisors = divisor(A).intersection(divisor(B))
    divisors = sorted(divisors)[::-1]
    print(divisors[K-1])

if __name__ == '__main__':
    main()

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

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

j = 0

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

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

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

Solution (Python):
a,b,k=map(int,input().split())
A=set()
for i in range(1,a+1):
    if a%i==0:
        A.add(i)
B=set()
for j in range(1,b+1):
    if b%j==0:
        B.add(j)
ans=A & B
ans2=list(ans)
ans3=sorted(ans2, reverse=True)

print(ans3[k-1])

Solution (Python):
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[len(ans)-k])

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

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

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

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

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


print(ans_l[-k])

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

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

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

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

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

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

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

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

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

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


main()

Solution (Python):
a = list(map(int,input().split()))
b = []

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

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

Solution (Python):
a,b,k = map(int, input().split())
num = min(a,b)
while k > 0:
    if a % num == 0 and b % num == 0:
        k -= 1
    num -= 1
print(num+1)