Problem:


Score : 200 points

Problem Statement

You are given positive integers A and B.

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

The input guarantees that there exists such a number.

Constraints

All values in input are integers.

1 \leq A, B \leq 100

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

K \geq 1

Input

Input is given from Standard Input in the following format:

A B K

Output

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

Sample Input 1

8 12 2

Sample Output 1

2

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

Sample Input 2

100 50 4

Sample Output 2

5

Sample Input 3

1 1 1

Sample Output 3

1



Sample input:
8 12 2


Sample output:
2

Submission status: Accepted

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

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

k = 0
min = min(A, B)

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

Submission status: Accepted

Solution code:
def euq(A, B):
    while B> 0:
        A, B = B, A % B
    return A

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

r = euq(A, B)
R = []
for i in range(1, r+1):
    if r % i == 0:
        R.append(i)
print(R[-C])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

n = 0
for i in range(max(A, B), 0, -1):
    if A % i != 0 or B % i != 0:
        continue
    n += 1
    if n == K:
        break
print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
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])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
 
count = 0
index = 0
 
if A >= B:
  for i in reversed(range(1, B+1)):
    if A % i == 0 and B % i == 0:
      index = i
      count = count+1
      if count == K:
        break
elif A < B:
    for i in reversed(range(1,A+1)):
      if A % (i) == 0 and B % (i) == 0:
        index = i
        count = count+1
        if count == K:
          break
  
print(index)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input = input()
a,b,c = map(int,input.split())
counter = 0
for x in range(min(a,b),0,-1):
  if(a%x==0 and b%x == 0):
    counter += 1
    if(counter == c):
      print(x)
      break

Submission status: Accepted

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

Submission status: Accepted

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

A,B,K = list(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:
# -*- coding: utf-8 -*-

# 整数の入力
# スペース区切りの整数の入力
a, b, k = map(int, raw_input().split())

m = max(a,b)
count = 0
array = []
for i in range(1, m+1):

    if a%i==0 and b%i==0:
        count += 1
        array.append(i)

print array[-k]

Submission status: Accepted

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

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

solve()

Submission status: Accepted

Solution code:
A, B, K = [int(_) for _ 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)
            exit(0)

Submission status: Accepted

Solution code:
A, B ,K  = (int(x) for x in input().split())
i = 1
ans = []
while True:
    if min(A,B) < i:
        break
    if (A % i == 0) & (B % i == 0):
        ans.append(i)
    i = i + 1
print(ans[len(ans)-K])

Submission status: Accepted

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

Submission status: Accepted

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

if int(nums[0]) >= int(nums[1]):
  min = int(nums[1])
else:
  min = int(nums[0])
  
count = 0
for i in range(min):
  if int(nums[0]) % min == 0 and int(nums[1]) % min == 0:
    count += 1
    if int(nums[2]) == count:
      print(min)
    else:
      min -= 1
  else:
    min -= 1

Submission status: Accepted

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

Submission status: Accepted

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

def divlist(x):
  numbers = []
  divX = []
  try:
    for i in range(1,x+1):
      numbers.append(i)
      if x % i == 0:
        divX.append(i)
    divX = set(divX)
    return divX
  except ZeroDivisionError:
      print("ZeroDivisionError!!")

divA = divlist(A)
divB = divlist(B)
common = list(divA & divB)
common = sorted(common)

#print("divA:", divA)
#print("divB:", divB)
#print("common:", common)
print(common[-K])

Submission status: Accepted

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

Submission status: Accepted

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

    divisors.sort()
    return divisors

input = [int(item) for item in input().split()]
a, b, k = input
divisors = make_divisors(a)

th = 0
for i, item in enumerate(divisors[::-1]):
  if b % item == 0:
    th += 1
  if th == k:
    print(item)
    break

Submission status: Accepted

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

print(ls[-k])

Submission status: Accepted

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

def divisor_list(n):
    ret = set()
    i=1
    while i*i <= n:
        if n % i == 0:
            ret.add(i)
            ret.add(n // i)
        i += 1
    return ret

DA = divisor_list(A)
DB = divisor_list(B)

# print(DA)
# print(DB)
COM = list(set(DA) & set(DB))
COM.sort(reverse=True)
# print(COM)
print(COM[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def find_divisor(n):
    return [i for i in range(1,n+1) if n%i == 0]

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

if (a<b):
    a,b = b,a

gcd = gcd(a,b)
cd_list = find_divisor(gcd)[::-1]

print(cd_list[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

print(items[-K] if len(items) >= K else items[0])

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())
listA = []
listB = []

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

A_B = set(listA) & set(listB)
listA_B = list(A_B)
listA_B.sort(reverse = True)

print(listA_B[K-1])

Submission status: Accepted

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

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

print(i)

Submission status: Accepted

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

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

print(ans[-k])

Submission status: Accepted

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

else :
    for b in range(B):
        if A%(b+1)==0 and B%(b+1)==0:
            X.append(b+1)
        else:
            continue
print(X[-K])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
li = list(map(int,input().split()))
a = li[0]
b = li[1]
c = li[2]

s = []

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

l =len(s)
print(s[l-c])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
cnt = 0
ans = 1
cntlist = []

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
count = 0
ans = min(a,b)
while count != k:
    if a%ans == b %ans == 0:
        count += 1
    ans -= 1
print(ans+1)

Submission status: Accepted

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

temp = 0
temp1 = 0
divisor = []
counter = 0

if A >= B:
  temp = A
  temp1 = B

else:
  temp = B
  temp1 = A

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

for j in (reversed(divisor)):
  if temp % j ==0:
    counter += 1
    if counter == times:
      print(j)
      break

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:
in_str = input()
a,b,k = (int(x) for x in in_str.split(' '))
x = min(a,b) + 1
while k > 0:
  x += -1  
  if a % x == 0 and b % x == 0:
    k -= 1
print (x)

Submission status: Accepted

Solution code:
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)


def main():
    A, B, K = map(int, input().split())
    C = gcd(A, B)
    divs = [1, C]
    i = 2
    while i**2 <= C:
        if C % i == 0:
            divs.append(i)
            if C // i != i:
                divs.append(C//i)
        i += 1
    divs.sort(reverse=True)
    print(divs[K-1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    a, b, c = list(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[-c])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys


args = str(input()).split(" ")

A = int(args[0])
B = int(args[1])
flag = int(args[2])

divided_num = A
if A > B:
    divided_num = B

while flag > 0:
    if ((A % divided_num) == 0) and ((B % divided_num) == 0):
        result = divided_num
        flag = flag - 1
    divided_num = divided_num - 1

print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  6 16:28:37 2019

@author: iwata
"""

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

if A >= B:
    for i in reversed(range(B+1)):
        rema1 = A%i
        remb1 = B%i
        if rema1==0 and remb1==0:
            count = count +1
        if K == count:
            print(i)
            break
else:
    for j in reversed(range(A+1)):
        rema = A%j
        remb = B%j
        if rema==0 and remb==0:
            count = count +1
        if K == count:
            print(j)
            break

Submission status: Accepted

Solution code:
data = input().split()
A = int(data[0])
B = int(data[1])
k = int(data[2])
ans = []
i = 1
ma = max(A,B)

while i <= ma:
  if (A % i == 0) & (B % i == 0):
    ans.append(i)
  i += 1
ind = len(ans)

print(ans[ind - k ])

Submission status: Accepted

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

Submission status: Accepted

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

if a <= b:
    start_num = a
else:
    start_num = b
cnt = 0
for num in range(start_num, 0, -1):
    if (a % num == 0) and (b % num == 0):
        cnt += 1
        if cnt == c:
            print(num)

Submission status: Accepted

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

print(ans_list[-K])

Submission status: Accepted

Solution code:
def main():
    a, b, k = map(int, input().split())
    for i in range(min(a, b), 0, -1):
        if a % i != 0 or b % i != 0:
            continue
        k -= 1
        if k == 0:
            print(i)
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc120/tasks/abc120_b
def y(p):
    r = set()
    for i in range(1, p + 1):
        if p % i == 0:
            r.add(i)
    return(r)

a, b, k = [int(x) for x in input().split()]
print(sorted(list(y(a) & y(b)))[-k])

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, 101):
    if A % i == 0 and B % i == 0:
        l.append(i)
        
l.sort(reverse = True)

print(l[K - 1])

Submission status: Accepted

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

val = 1
valSet = []
while True:
  if A % val == 0 and B % val == 0:
    valSet.append(val)
  val += 1
  if val > min(A, B):
    break
print(valSet[-1*K])

Submission status: Accepted

Solution code:
val = input().split(" ")
A = int(val[0])
B = int(val[1])
K = int(val[2])
 
arr1 = [i for i in range(1,A + 1) if A % i == 0]
arr2 = [j for j in range(1,B + 1) if B % j == 0]
 
result = list(set(arr1) & set(arr2))
result.sort(reverse=True)
print(result[K - 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c = map(int,input().split(" "))
count = 0
d = min(a,b)
while True:
    if a % d == 0 and b % d == 0:
        count += 1
        if count == c:
            print(d)
            exit()
    d -= 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
from math import sqrt

def li(): return map(int, stdin.readline().split())




A, B, K = tuple(li())
count = 0
g = min(A, B)
can = []
cnt = 0
for i in range(1, g + 1):
    if A % i == 0 and B % i == 0:
        
        
        can.append(i)



print(can[-K])

Submission status: Accepted

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

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

print(temp[-K])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

results.reverse()
print(results[c - 1])

Submission status: Accepted

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

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

ans = max(A, B)
while True:
    if A % ans == 0 and B % ans == 0:
        K -= 1
        if K == 0:
            print(ans)
            exit()
    ans -= 1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
line = input().split(' ')
A = int(line[0])
B = int(line[1])
K = int(line[2])

def KthCommonDivisor(A,B,K):
    n = min(A,B)
    c = 0
    for i in range(n, -1, -1):
        if A % i == 0 and B % i == 0:
            c += 1
            if c == K:
                return i

res = KthCommonDivisor(A,B,K)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

if A>B:
  x = B
else:
  x = A

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

print(x+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(result[-K])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(i)

Submission status: Accepted

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

Submission status: Accepted

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

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

main()

Submission status: Accepted

Solution code:
def compute():
  from sys import stdin
  A, B, K = list(map(int, stdin.readline().split()))
  
  cur = min(A,B) + 1
  while K>0 and cur>0:
    cur -= 1
    if (A%cur==0) and (B%cur==0):
      K-=1
  
  print(cur if K<1 else -1)

if __name__ == "__main__":
  compute()

Submission status: Accepted

Solution code:

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

limit = min(a, b)

answer = []


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

answer.sort(reverse=True)


print(answer[c-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Mar  4 22:49:08 2019

@author: yuta
"""

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

Submission status: Accepted

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

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)
        
l = sorted(l, reverse = True)
print(l[k - 1])

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)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
num= [int(i) for i in input().split()]
max_n = min(num[0],num[1])
a = sorted(list(range(1,max_n+1)),reverse=True)
print([i for i in a if (num[0]%i==0 and num[1]%i==0)][num[2]-1])

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines

A, B, K = [int(i) for i in readline().split(' ')]

j = -1
a = A
b = B
if a < b:
  a,b = b,a
while True:
  j =  a % b
  if j == 0:
    break
  a = b
  b = j

pn = list()
if K == 1:
  print(b)

j = 2
for i in range(b//2, 0, -1):
  if b % i == 0:
    if j == K:
      print(i)
    j += 1

Submission status: Accepted

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

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)

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

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

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

if __name__=='__main__':
  main()

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=[int(x) for x in input().split()]
index=0
for ans in range(min(a,b),0,-1):
    if a%ans==0 and b%ans==0:
        index+=1
    if index==k:
        print(ans)
        break

Submission status: Accepted

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

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

print(ans[-k])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = []
ans = []
a, b, k = list(map(int, input().split()))
l.append(a)
l.append(b)
i = 1

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

print(ans[-k])

Submission status: Accepted

Solution code:
l = []
ans = []
a, b, k = list(map(int, input().split()))
l.append(a)
l.append(b)
i = 1

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

if len(ans) == 0:
    print(1)
else:
    print(ans[-k])

Submission status: Accepted

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

Submission status: Accepted

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

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

x = gcd(A, B)
y = []

for i in range(x):
    if x % (i + 1) == 0:
        y.insert(0, i + 1)

print(y[K - 1])

Submission status: Accepted

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

Submission status: Accepted

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

t_list = []
for i in range(1, 10 ** 5):
    if A%i == 0 and B%i == 0:
        t_list.append(i)
           
print(t_list[-K])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
a_list=list(set([i for i in range(1,a+1) if not a%i]))
b_list=list(set([j for j in range(1,b+1) if not b%j]))
c=[]
for i in a_list:
    for j in b_list:
        if i==j:
            c.append(i)
c.sort(reverse=True)
print(c[k-1])