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

"""
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

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

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

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

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

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

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

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

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

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

Solution (Python):



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



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)



seki = set_A & set_B

seki = list(seki)

seki.sort(reverse=True)

print(seki[K - 1])

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

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

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

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

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

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

Solution (Python):


"""
Created on 2019/3/3
Solved on 2019/3/3
@author: shinjisu
"""






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  
ans = prob_B()
print(ans)




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

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

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

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

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

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

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

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

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

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

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

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

common_divisor = []



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


copy_common_divisor = list(reversed(common_divisor))
print(copy_common_divisor[k - 1])

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

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

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

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

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

c = []

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

print(c[k-1])

Solution (Python):
def gcd(m,n):
    x=max(m,n)
    y=min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
            return z

nums=list(map(int,input().split(" ")))
g=gcd(nums[0],nums[1])
arr=[0 for i in range(100)]
a=0
for i in range(100):
    i+=1
    if nums[0]%i==0 and nums[1]%i==0:
        arr[a]=i
        a+=1
        if i==g:
            print(arr[a-nums[2]])
            break

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

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

print(cd[-(k)])

Solution (Python):


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

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

print(lst[-k])

Solution (Python):
int_list = input().split()

a = int(int_list[0])
b = int(int_list[1])
k = int(int_list[2])

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

Solution (Python):






import sys





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





def yakusuu(x):
    yakusuu_array = []

    for i in range(1, x+1):
        if x % i == 0:
            yakusuu_array.append(i)
    
    return yakusuu_array





y_list = sorted(list(set(yakusuu(A)) & set(yakusuu(B))), reverse=True)





print(y_list[K-1])

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

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

divisor = []

for elemA in divisorA:
	divisor += filter(lambda elem: elem == elemA, divisorB)	

divisor = sorted(divisor)
divisor = divisor[::-1]


print( divisor[k-1] )

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

print(nums[-K])

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

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

Solution (Python):
from sys import stdin
A, B, C = [int(x) for x in stdin.readline().rstrip().split()]

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

Solution (Python):
a,b,c = map(int, input().split())
i=1
count = 0
x=[]
for i in range(101):
  try:
    if a%i==0 and b%i==0:
      count+=1
      x.append(i)
  except ZeroDivisionError:
    pass
  i+=1
print(x[-c])

Solution (Python):
inp = list(map(int,input().split(" ")))
i = min(inp[0],inp[1])
k_=0
k_list = list()
for k in range(1,i+1):
    if inp[0]%k ==0:
        if inp[1]%k==0:
            k_+=1
            k_list.append(k)
print(k_list[-inp[2]])

Solution (Python):

import sys



def solve(lines):
    A,B,K = map(int, lines.pop(0).split(' '))
    x = min(A,B)
    res = []
    for i in range(x,0,-1):
        if A%i == 0 and B%i == 0:
            res.append(i)
    print(res[K-1])

lines = [x.strip() for x in sys.stdin.readlines()]                                                                                                            
                                                                                                                                                              



solve(lines)

Solution (Python):

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

count = 0
i = 1

ans = []
while i <= a and i <= b:
    if a % i == 0 and b % i == 0:
        ans.append(i)
    i += 1


print(ans[-k])

Solution (Python):
import fractions


def main():
    a = list(map(int, input().split()))
    b = fractions.gcd(a[0], a[1])
    c = b
    for i in range(a[2]-1):
        while True:
            c -= 1
            if b % c == 0:
                break
    print(c)


main()

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

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


print(divs[-K])

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

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

print(i)

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

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

count = 0
i = 1
dividable_numbers = []
while True:
    if a % i == 0 and b % i == 0:
        count += 1
        dividable_numbers.append(i)

    if a < i or b < i:
        break

    i += 1

print(dividable_numbers[-k])

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

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

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

count = 0
cand = []
denom = 0

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

print(cand[-K])

Solution (Python):



import sys
import math





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



count = 0
num = min(a, b) + 1
while count < k:
    num -= 1
    if a % num == 0 and b % num == 0:
        count += 1

print(num)

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

Solution (Python):

A,B,K  = map(int, input().split(" "))
count = 0
i = 1
tempList = []
for i in range(1,200) :
    if A%i == 0 and B%i == 0:
        tempList.append(i)
print(tempList[-K])

Solution (Python):
a=input()
A=int(a.split()[0])
B=int(a.split()[1])
K=int(a.split()[2])

a=0
if(A>B): i=A
else: i=B
count=0
while(a==0):
  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())
res = []
for i in range(1,min(a,b)+1):
  if a%i==0 and b%i == 0:
    res.append(i)
print(res[-k])

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

Solution (Python):
a, b, k = map(int,input().split())
a_div = []
b_div = []
for i in range(1, a + 1, 1):
  if a % i == 0:
    a_div.append(i)
for i in range(1, b + 1, 1):
  if b % i == 0:
    b_div.append(i)
common_div = []
common_div = set(a_div) & set(b_div)
common_div_lst = list(common_div)
common_div_lst.sort(reverse = True)
print(common_div_lst[k - 1])

Solution (Python):
a,b, c = map(int, input().split())
turn_a =[x for x in range(1,a+1)]
turn_b=[y for y in range(1,b+1)]
ans=[x for x,y in zip(turn_a,turn_b) if a%x==0 and b%y==0]
ans.reverse()
print(ans[c-1])

Solution (Python):


import sys
sys.setrecursionlimit(10000)

input = sys.stdin.readline

def debug(*args, **kdws): print(*args, file=sys.stderr, **kdws)

A, B, K = [int(x) for x in input().split()]
debug("*******")
debug(A, B, K)
c = 0

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

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

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

Solution (Python):
a,b,k=map(int,input().split())
s=set()
x=1
while(x*x<=a):
  if(a%x==0):
    s.add(x)
  if(a//x!=x and a%(a//x)==0):
    s.add(a//x)
  x+=1
x=1
while(x*x<=b):
  if(b%x==0):
    s.add(x)
  if(b//x!=x and b%(b//x)==0):
    s.add(b//x)
  x+=1
s=list(sorted(s))
s.sort(reverse=True)
count=0
for i in range(len(s)):
    if(a%s[i]==0 and b%s[i]==0):
        count+=1
    if(count==k):
        print(s[i])
        exit()

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

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

def divisors(d):
    ret = []
    for a in range(1, d + 1):
        if d % a == 0:
            ret.append(a)
    return ret

l = raw_input().split()
a = int(l[0])
b = int(l[1])
k = int(l[2])

d = gcd(a, b)
ret = divisors(d)

print(ret[-k])

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

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

Solution (Python):
N = list(map(int,input().split()))
count = 0
for i in range(min(N[0],N[1]),-1,-1):
  if count>N[2]:
    break
  elif i!=0 and N[0]%i==0 and N[1]%i==0:

    count+=1
  if count==N[2]:
    print(i)
    count+=1

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

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

Solution (Python):
from sys import stdin
a, b, k = [int(x) for x in stdin.readline().rstrip().split()]
divides=[]
for i in range(1,101):
    if a%i == 0 and b%i == 0:
        divides.append(i)
divides.sort(reverse=True)
print(divides[k-1])

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

smaller = min(A, B)

lst = []
cnt = 1 
for i in range(1, smaller+1, 1):
  if A % i == 0 and B % i == 0:
    lst.append(i)
sorted_lst = sorted(lst,reverse=True)

print(sorted_lst[K-1])

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

Solution (Python):

a,b,k = list(map(int,input().split()))
lw = min(a,b)
for i in range(lw,0,-1):
    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())
count = min(a, b)
flag = 0
while True:
    if a % count == 0 and b % count % count == 0:
        flag += 1
        if flag == k:
            print(count)
            break
    count -= 1

Solution (Python):
a,b,k=map(int,input().split())
print(list(filter(lambda x:a%x+b%x==0, [i for i in range(min(a,b),0,-1)]))[k-1])

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

st = max(A, B)
cnt = 0
for i in range(st)[::-1]:
    j = i + 1
    if (A%j==0) & (B%j==0):
        cnt += 1
    if cnt == K:
        ans = j
        break

print(ans)

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

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

Solution (Python):
import sys
input = sys.stdin.readline

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

M = max(A,B)
N = min(A,B)

ans = []
while(N != 0):
    M, N = N, M%N
s = 0
MAX = M + 0
current = 0
for i in range(1,101):
    if M%i == 0:
        ans.append(int(i))
ans.sort(reverse=True)
print(ans[K-1])

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

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

print([i for i in range(100, 0, -1) if A%i == B%i == 0][K-1])

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

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

        if count == K:
            answer = i
            break

print(answer)

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

i=1
n=100

while i<=K:
  
  if A%n == 0 and B%n ==0:
    if i==K:
      break
    else:
      i+=1
      n-=1
  else:
    n-=1
print(n)

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

for i in range(1, 101):
	x = a / i
	y = b / i
	if x.is_integer() == True and y.is_integer() == True:
		li.append(i)

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

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

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

print([i for i in range(100, 0, -1) if A%i == B%i == 0][K-1])

Solution (Python):
a, b, k = map(int, input().split())
c = 1
i = 0
ans = []
while c <= min(a, b):
    if a % c == 0 and b % c == 0:
        ans.append(c)
        i += 1

    c += 1

print(ans[-k])

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

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

print(ans)

Solution (Python):
a, b, k = map(int, input().split())
l1 = [i for i in range(1, a+1) if (a % i == 0)]
l2 = [i for i in range(1, b+1) if (b % i == 0)]
l = list(set(l1) & set(l2))
l.sort(reverse = True)
print(l[k-1])

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

Solution (Python):
A,B,K = map(int,input().split())
if A>B:
  L=A
else:
  L=B
D = L

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

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

if A>B:
    for i in range(2,B+1):
        if A%i==0 and B%i==0:
            num.append(i)
            count =count+1
else:
    for i in range(2,A+1):
        if A%i==0 and B%i==0:
            num.append(i)
            count =count+1


print(num[count-K])

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

a = int(a)
b = int(b)
k = int(k)


small = min(a,b)

list = []

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

order = len(list)-k

print(list[order])

Solution (Python):
A, B, K = (int(i) for i in input().split()) 
 
a = set()
b = set()
 
for i in range(1, A + 1):
    if A % i == 0:
        a.add(i)
 
for i in range(1, B + 1):
    if B % i == 0:
        b.add(i)

c = list(a & b)
c.sort()
c.reverse()
print(c[K-1])

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

Solution (Python):
a,b,k = [int(x) for x in input().split()]
c = []
t = a if a < b else b
for i in range(1,t+1):
    if a%i == 0 and b%i == 0:
        c += [i]
print(c[-k])

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

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

for i in range(len(al)):
    if al[i] in bl:
        cl.append(al[i])

print(cl[-k])

Solution (Python):
nums = [int(s) for s in input().split(' ')]
if nums[0]>nums[1]:
  a = nums[0]
  b = nums[1]
else:
  a = nums[1]
  b = nums[0]
c= nums[2]

while b>0:
  tmp = a%b
  a = b
  b = tmp

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

Solution (Python):
from sys import stdin

abk = [int(i) for i in stdin.readline().rstrip().split(" ")]


commons = []
for i in range(1,max(abk[0],abk[1])+1):
    if (abk[0] % i) == 0 and (abk[1] % i) == 0:
        commons.append(i)
print(commons[-abk[2]])

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

divisor = min(a, b)
cnt = 0
while cnt != k:
    if int(a % divisor) == 0 and int(b % divisor) == 0:
        cnt = cnt + 1
    divisor = divisor - 1

print(divisor + 1)

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

if a==1 or b==1:
    print(1)
    exit()
    
for d in range(1,c+1):
    if a%d==0 and b%d==0:
            y.append(d)

print(y[-k])

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

Solution (Python):
import sys


A,B,K = sys.stdin.readline().strip().split()
A = int(A)
B = int(B)
K = int(K)

cnt=0
num=1
N = []
while cnt<=100:
    if(A%num==0 and B%num==0):
        N.append(num)
    num += 1
    cnt += 1

print(N[-K])

Solution (Python):
a,b,k=input().split()
A=int(a)
B=int(b)
K=int(k)
cnt=0
for i in range(A,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())
count = 0
for x in range(min(a,b)+1,0,-1):
    if(a%x ==0 and b%x==0):
        count += 1
        if(count == k):
            print(x)
            break

Solution (Python):
l = list(map(int,input().split()))

if l[0] < l[1]:
    mini = l[0]
else:
    mini = l[1]

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

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

Solution (Python):
from fractions import gcd

def yakusuu(a):
    yakusuu = list()
    for i in range(1,a+1):
        if a % i == 0:
            yakusuu.append(i)
    return yakusuu

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

ans = yakusuu(gcd(A,B))[-K]
print(ans)

Solution (Python):
a,b,k=map(int,input().split())
divisor_list = []
for n in a, b:
    divisor_list.append(1)
    for i in range(2, n // 2 + 1):
        if n % i == 0:
            divisor_list.append(i)
    divisor_list.append(n)
l = sorted([x for x in set(divisor_list) if divisor_list.count(x) > 1], key=divisor_list.index)
print(l[-k])

Solution (Python):
a, b, k = list(map(int, input().split()))
div_a = [d for d in range(1, a+1) if a % d == 0]
div_b = [d for d in range(1, b+1) if b % d == 0]
common = sorted(list(set(div_a) & set(div_b)), reverse=True)
print(common[k-1])

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

Solution (Python):


import sys

def gcd(a, b):

    c = min(a, b)
    d = max(a, b)
    r = 0    
    while True:
        r = d % c
        if r == 0:
            break
        d = c
        c = r

    return c


def parse_input(lines_as_string = None):


    lines = []
    if lines_as_string is None:
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    tokens = lines[0].split(" ")
    a = int(tokens[0])
    b = int(tokens[1])
    k = int(tokens[2])

    return (a, b, k)


def solve(a, b, k):

    tmp = gcd(a, b)

    div = tmp - 1
    order = 1
    current = tmp
    while div > 0:
        if order == k:
            break

        if tmp % div == 0:
           order += 1
           current = div

        div -= 1

    return current

def main():
    

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

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

o.sort(reverse=True)
print(o[k-1:k][0])

Solution (Python):

a, b, k = map(int, input().split())
if a > b:
    t = a
    a = b
    b = t

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

Solution (Python):

def divisor_list(n):
    i=1
    l=[]
    while i<=n:
        if n%i == 0:
            l.append(i)
        i = i+1
    return l


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


s1 = set(divisor_list(a))
s2 = set(divisor_list(b))
s3 = list(s1 & s2)
s3.sort(reverse=True)
print(s3[k-1])

Solution (Python):
def factorize(n):
    n_list = []
    for i in range(n):
        x = i + 1
        if n % x == 0:
            n_list.append(x)
    return n_list


if __name__ == '__main__':
    A, B, C = input().split()
    a_list = factorize(int(A))
    b_list = factorize(int(B))
    and_list = list(set(a_list) & set(b_list))
    and_list.sort(reverse=True)
    print(and_list[int(C) - 1])