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-----
8 12 2

-----Sample Output-----
2

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

Difficulty: introductory

Starter code:

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

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

div_A = make_divisors(A)
div_B = make_divisors(B)

l = []
for i in div_A:
    for j in div_B:
        if i == j:
            l.append(i)
print(l[-K])

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

c = []

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

print(c[-k])

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

def cf(x1,x2):
    cf=[]
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

print(cf(A,B)[-(K)])

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

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

ans = l[-1*k]    
print(ans)
    



A, B, K = map(int, input().split())
lst = []
for n in range(1, min(A, B)+1):
    if B % n == 0:
        lst.append(n)
lst2 = []
for m in lst:
    if A % m == 0:
        lst2.append(m)
print(sorted(lst2, reverse=True)[K-1])

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

# AもBも割り切る正整数のうち、K番目に大きいものを出力せよ。

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

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

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

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

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

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

print((ans[-K]))


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

common_list = []
min_AB = min(A, B)

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

common_list.sort(reverse=True)
print(common_list[K-1])

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

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

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)

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

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

print(i_list[-K])

# https://atcoder.jp/contests/abc120/tasks/abc120_b

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

min_a_b = min(a, b)
divisor_list = []

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

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

a,b,k=list(map(int,input().split()))
n=max(a,b)
numlist=[]
for i in range(1,n+1):
    if a%i==b%i==0:
        numlist.append(i)
numlist.sort(reverse=True)
print((numlist[k-1]))


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)

k = -1 * k

print(ans[k])

A, B, K = map(int, input().split())
print([i for i in range(1, 101) if A % i + B % i < 1][-K])

def atc_120b(ABK: str) -> int:
    a, b, k = map(int, ABK.split(" "))

    result_value = min(a, b)
    letter_count = 0

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

    return i

ABK_input = input()
print(atc_120b(ABK_input))

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

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


a, b, k = list(map(int, input().split()))
table = []
divisor_a = divisor(a)
divisor_b = divisor(b)
for i in divisor_a:
    if i in divisor_b:
        table.append(i)
table.sort(reverse=True)
print((table[k-1]))


a,b,k = map(int,input().split())
li = []
def cf(a,b):
    for i in range(2,min(a,b)+1):
        if a % i == 0 and b % i == 0:
            li.append(i)
    return li

cf(a,b)
li.insert(0,1)
li.reverse()
print(li[k-1])

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

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

a,b,k=list(map(int,input().split()))
import math
print((make_divisors(math.gcd(a,b))[-k]))


a, b, k = list(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]))


# import math
# import statistics
# import itertools
# a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
A,B,K= map(int,input().split())
# f = list(map(int,input().split()))
# g = [input().split for _ in range(a)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen
count=0
wari=min(A,B)
while True:
    if A%wari==0 and B%wari==0:
        count+=1
    if count==K:
        print(wari)
        return
    wari-=1


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


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


import math

num1, num2, target = list(map(int, input().split()))

number = math.gcd(num1, num2)

table = []
for j in range(1, number+1):
    if number % j == 0:
        table.append(j)
list.sort(table, reverse=True)

print((table[target-1]))


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

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

div_A = make_divisors(A)
div_B = make_divisors(B)

# l = []
# for i in div_A:
#     for j in div_B:
#         if i == j:
#             l.append(i)
# print(l[-K])
print((sorted(set(div_A)&set(div_B))[-K]))


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

a, b, k = list(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)
c.reverse()
print((c[k-1]))


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:
            print(i)

A,B,K=list(map(int,input().split()))
ans=0
n=100
while True:
    if A%n==0 and B%n==0:
        ans+=1
        if ans==K:
            print(n)
            return
    n-=1


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(S[-K])

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


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

list = []

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

print(list[-K])

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

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

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

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

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

print(l[-K])

A, B, K = list(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
  if count == K:
    print(i)
    return


a, b, k = map(int, input().split())
def answer(a: int, b: int, k: int) -> int:
    result = []
    if a > b:
        for i in range(1, b + 1):
            if a % i == 0 and b % i == 0:
                result.append(i)
        return result[len(result) - k]
    else:
        for i in range(1, a + 1):
            if a % i == 0 and b % i == 0:
                result.append(i)
        return result[len(result) - k]

print(answer(a, b, k))

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

l = []

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

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

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

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

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

res = 0

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

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

mylist = []

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

print((mylist[-k]))


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

lists = []

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

print(lists[-K])

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

def main():
    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])


def __starting_point():
    main()
__starting_point()

from typing import Set


def divisors(n: int) -> Set[int]:
    divs = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            divs.add(i)
            divs.add(n // i)
        i += 1
    return divs


def answer(a: int, b: int, k: int) -> int:
    divisors_a = divisors(a)
    divisors_b = divisors(b)

    common_divisors = list(divisors_a & divisors_b)
    common_divisors.sort()

    return common_divisors[-k]


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


def __starting_point():
    main()

__starting_point()

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

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

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

lst=[]
def divisor(n,m):
	if n>m:
		n,m=m,n
	for i in range(1,m+1):
		if n%i==0 and m%i==0:
			lst.append(i)
	lst.reverse()
	print(lst[K-1])
    
divisor(A,B)

def __starting_point():
    A, B, K = list(map(int, input().split()))
    a_ans = []
    b_ans = []
    for a in range(1, A+1):
        if A%a == 0:
            a_ans.append(a)
    for b in range(1, B+1):
        if B%b == 0:
            b_ans.append(b)
    ans = list(set(a_ans) & set(b_ans))
    ans.sort(reverse=True)

    print((ans[K-1]))

__starting_point()

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


def __starting_point():
    main()
__starting_point()

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

A, B, K = map(int, input().split())
cnt = 0
for i in range(max(A, B)):
    num = max(A, B) - i
    if A % num == 0 and B % num == 0:
        cnt += 1
    # print(num, cnt)
    if cnt == K:
        break
print(num)

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

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

mylist = []

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

print((mylist[-k]))


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

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


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

def ans120(A:int, B:int, K:int):
    l=sorted([A,B])
    ans_list=[]
    for i in range(1,l[1]+1):
        if A%i==0 and B%i==0:
            ans_list.append(i)
    return ans_list[-K]

print(ans120(A,B,K))

A, B, K = map(int, input().split())
def gcd(a, b):
  while b > 0:
    temp = a % b
    a = b
    b = temp
  return a
C= gcd(A,B)
i = C + 1
while K > 0:
  i -= 1
  if C % i == 0:
    K -= 1
print(i)

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

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

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

def ans120(A:int, B:int, K:int):
    if A>=B:
        n=A
    else:
        n=B
    ans_list=[]
    for i in range(1,n+1):
        if A%i==0 and B%i==0:
            ans_list.append(i)
    return ans_list[-K]

print((ans120(A,B,K)))


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

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


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

        
print(array[-K])

import sys
input = sys.stdin.readline


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

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

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



def __starting_point():
    main()


__starting_point()

integer1, integer2, term = map(int, input().split())
term_value = max(integer1, integer2)
largest_term = 0
while term_value <= 100:
    if integer1 % term_value == 0 and integer2 % term_value == 0:
        largest_term += 1
    if term == largest_term:
        break
    term_value -= 1
print(term_value)

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

a_list, b_list = [], []

for ai in range(1,a+1):
    if a % ai == 0:
        a_list.append(ai)
for bi in range(1,b+1):
    if b % bi == 0:
        b_list.append(bi)

list_ = [b for b in b_list if b in a_list]
print(list_[-k])

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

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

a_divisor = divisor(A)
b_divisor = divisor(B)

print(sorted(list(set(a_divisor) & set(b_divisor)), reverse=True)[K-1])

# 整数A,B AもBも割れる整数でK番目に大きいもの

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

warerukazu = []

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

print(warerukazu[-K])

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

divid_number = []
for X in range(1,100+1):
    if A % X ==0 and B % X == 0:
        divid_number.append(X)

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


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

min_a_b = min(a, b)
divisor_list = []

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

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




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

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

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

print((c_f(A,B)))


A,B,K = map(int,input().split())
# print(A,B,K)
A_list = []
ans_list = []

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

for n in A_list:
    if B % n == 0 :
        ans_list.append(n)
# print(ans_list)
print(ans_list[-K])

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

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

n = min(a,b)

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

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

a, b, k = list(map(int,input().split()))
c = []

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

# for i in range(1, b + 1):
#     if b % i == 0:
#         c.append(i)
#     else:
#         pass

print((c[-k]))


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

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

# B k-th common Divisor
a, b, k = list(map(int, input().split()))
ans = []
for i in range(1, 101):
    if a % i == 0:
        if b % i == 0:
            ans.append(i)
ans = sorted(ans)
print((ans[-k]))


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

min_a_b = min(a, b)
divisor_list = []

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

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


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

X = min(A,B)
Y = []

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

print(Y[-K])

A,B,K=list(map(int,input().split()))
for x in range(100,0,-1):
    if A%x==0 and B%x==0:
        K-=1
    if K==0:
        print(x)
        break


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

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

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

print(i)


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

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

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

int1, int2, rank = map(int, input().split())
kouyaku_list = []
for i in range(1, 100 + 1):
    if int1 % i == 0 and int2 % i == 0:
        kouyaku_list.append(i)

print(kouyaku_list[-rank])

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

count = 0
n = min(a, b)

for i in reversed(range(1, n+1)):
    if a % i == 0 and b % i == 0:
        count += 1
        if count == k:
            ans = i

print(ans)

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

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


a,b,k = map(int,input().split())
# aの約数
a_divisor = []
# abの公約数
ab_divisor = []

# aで割れたら順次約数に追加
for i in range(1,a+1):
    if a % i == 0:
        a_divisor.append(i)

# aの約数でbが割れたら公約数に追加
for j in a_divisor:
    if b % j == 0:
        ab_divisor.append(j)
# リストの大きい方からK番目の数値を出力
print(ab_divisor[-k])

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

kouyakusuu = []

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

print(kouyakusuu[-K])


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

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

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

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

print((count_list[-K]))