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:
"""
# 標準入力取得
## 文字列
 = 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)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

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())
    cnt = 0
    i = max(A, B)
    while True:
        if (A % i) == 0 and (B % i) == 0:
            cnt += 1
            if cnt == K:
                print(i)
                exit()
        i -= 1

Submission status: Accepted

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

a_dis = [x for x in range(1,a+1) if a % x == 0]
b_dis = [x for x in range(1,b+1) if b % x == 0]

co_dis = sorted([i for i in a_dis if i in b_dis],reverse=True)

print(co_dis[k-1])

Submission status: Accepted

Solution code:
import fractions

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

p=fractions.gcd(A,B)

count=1

ans=p

for i in reversed(list(range(1,p))):
    if p%i==0:
        count+=1
        ans=i
    if count==K:
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import sqrt

x,y,k = map(int, input().split())

def getDivisors(a , b):
    a1 = set()
    a2 = set()
    for i in range(1,int(sqrt(a)+1)):
        if a%i == 0:
            a1.add(i)
            a1.add(a//i)
    for j in range(1,int(sqrt(b)+1)):
        if b%j == 0:
            a2.add(j)
            a2.add(b//j)
    return sorted(a1.intersection(a2))


print(getDivisors(x, y)[-k])

Submission status: Accepted

Solution code:
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)
        
d.reverse()
print(d[K-1])

Submission status: Accepted

Solution code:
a, b, k = list(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)
    break

Submission status: Accepted

Solution code:
import numpy as np
import math
a,b,k = input().split()
a = int(a)
b = int(b)
k = int(k)
count_k = 0
for d in range(100,0, -1):
    if a % d == 0 and b % d == 0:
        count_k += 1
        if count_k == k:
            break

print(d)

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

Submission status: Accepted

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

def gcd(a, b):
	while b != 0:
		a, b = b, a % b
	return a
	
num = gcd(A, B)
ans = []
for i in range(num, 0, -1):
  if num % i == 0:
    	ans.append(i)
      
print(ans[K - 1])

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
def calc(n):
    res = []
    for i in range(1,n+1):
        if not n % i:
            res.append(i)
    return set(res)
print(sorted(list(calc(a) & calc(b)))[-k])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n1, n2, n3 = [int(i) for i in input().split()]

n4 = min(n1, n2)
c5 = 0
r6 = 0
for i1 in range(n4):
    if (n1 % (n4 - i1) == 0) and (n2 % (n4 - i1) == 0):
        c5 += 1
        if c5 == n3:
            r6 = (n4 - i1)
            break

print(r6)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

num = min(a, b)

ans = []

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

print(ans[-k])

Submission status: Accepted

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

Submission status: Accepted

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


anss = []



c = max(a,b)

for i in range(1, c + 1):

    if a % i == 0 and b % i == 0:
        anss.append(i)


# print(anss[k-1])
print(anss[-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==0][-K])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(l[-k])

Submission status: Accepted

Solution code:
def abc():
    a, b, k = map(int, input().rstrip().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])


abc()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
    else:
        continue
print(c[-k])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
l = []
n = 1
while True:
    if a%n == 0 and b%n == 0:
        l.append(n)
    elif a < n or b < n:
        break
    n += 1

print(l[-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

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

a, b, k = map(int, input().split())
li = cf(a, b)
print(li[-k])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,k=map(int, input().split())
ans=[]
for i in range(max(a,b)):
    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())
counter = 0
for i in range(1,101)[::-1]:
    if A%i == 0 and B%i == 0:
        counter += 1
        if counter == K:
            print(i)
            break

Submission status: Accepted

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

if a < b:
    m = a
else:
    m = b

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

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

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

Submission status: Accepted

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

ans = []

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

ans2 = []

for j in ans:
    if b % j == 0:
        ans2.append(j)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(lower, 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())
l = [i for i in range(1, 101) if A%i == 0 and B%i == 0]
print(l[-K])

Submission status: Accepted

Solution code:
int_a, int_b, division_num = map(int, input().split())
division_count = 100
select_division = []
i = 1

while i < division_count:
    if int_a % i == 0 and int_b % i == 0:
        division_count += 1
        select_division.append(i)
    i += 1

print(select_division[-division_num])

Submission status: Accepted

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

if A < B:
    n = A
else:
    n = B

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

print(l[-K])

Submission status: Accepted

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

ans = []

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

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

Submission status: Accepted

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

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

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


#print(divisor)
print(divisor[len(divisor) - K])

Submission status: Accepted

Solution code:
def yakusu(n):
	l=int(n**0.5)
	ans=[]
	for i in range(1,l+1):
		if n%i==0:
			ans.append(i)
			ans.append(n//i)
	ans=list(set(ans))
	ans.sort()
	return ans

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

def resolve():
	A,B,K=map(int,input().split())
	g=gcd(A,B)
	print(yakusu(g)[-K])
resolve()

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
 
cnt = 0
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:
A, B, K = map(int, input().split())

count = 0
tmp = max(A, B)

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

Submission status: Accepted

Solution code:
import fractions as fr

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

k = 0

R = int(max(fr.gcd(A,B),1))

for i in range(R,0,-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())

tmp = []

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

tmp.reverse()
#print(tmp)
print(tmp[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
A, B, K = map(int, input().split(" "))
n_list = [A, B]
N = np.min(n_list)
for i in range(N, 0, -1):
    if (A % i == 0) & (B % i == 0):
        K -= 1
        if K == 0:
            print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

start = min(a,b)
order = 0

for i in range(start):
    if a % (start-i) == 0 and b % (start-i) == 0:
        order += 1
        if order == k:
            print(start-i)

Submission status: Accepted

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

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
  
A, B, K = map(int, input().split())
N = gcd(A, B)
print(make_divisors(N)[-K])

Submission status: Accepted

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

def func(M, L, K):
    count = 0

    for ans in reversed(range(1,L+1)):
        if M % ans == 0 and L % ans == 0:

            count += 1

            if count == K:
                print(ans)

if A > B:
    func(A, B, K)
else:
    func(B, A, K)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, k = list(map(int, input().split()))
i = min(a, b)
c = 1
while i != 0:
    if a % i == 0 and b % i == 0:
        if c == k:
            print(i)
            break
        c += 1
    i -= 1

Submission status: Accepted

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,K=map(int,input().split())
a=[]
b=[]
for i in range(A):
  if A%(i+1) == 0:
    a.append(i+1)
for ii in range(B):
  if B%(ii+1) == 0:
    b.append(ii+1)
s=set(a)&set(b)
print(sorted(list(s))[-K])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
ans = 0
mi = min(A, B)
k = 0

for _ in range(mi):
	if A%mi == 0 and B%mi ==0:
		ans = mi
		k += 1

	if k == K:
		break

	mi -= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for i in range(start, 0, -1):
  if all(x % i == 0 for x in AB):
    cnt += 1
    if cnt == K:
      break
print(i)

Submission status: Accepted

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

cnt = 0
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:
A, B, K = map(int, input().split())
a    = []
b    = []
same = []
for i in range(1, A+1):
    if A % i == 0:
        a.append(i)
for i in range(1, B+1):
    if B % i == 0:
        b.append(i)
for v_a in a:
    for v_b in b:
        if v_a == v_b:
            same.append(v_a)
            
same = sorted(same, reverse=True)
print(same[K-1])

Submission status: Accepted

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

count = []

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

print(count[-k])

Submission status: Accepted

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

for i in aa:
    if i in bb:
        common.append(i)
print(common[-k])

Submission status: Accepted

Solution code:
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
A, B, K = map(int, input().split())
ans = deque()

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

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
lista = [a for a in range(1, A + 1) if A % a == 0]
listb = [b for b in range(1, B + 1) if B % b == 0]
listc = sorted(list(set(lista) & set(listb)))

print(listc[-K])

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
lista = [a for a in range(1, A + 1) if A % a == 0]
listb = [b for b in range(1, B + 1) if B % b == 0]
listc = sorted(list(set(lista) & set(listb)))
#print(lista)
#print(listb)
#print(listc)

print(listc[-K])

Submission status: Accepted

Solution code:
def md(n):
    d=[]
    da=d.append
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            da(i)
            if i!=n//i:da(n//i)
    d.sort()
    return d
A,B,K = map(int,input().split())
c = sorted(set(md(A)) & set(md(B)),reverse = True)
print(c[K-1])

Submission status: Accepted

Solution code:
#Coding: Utf-8
A,B,K=map(int,input().split())
count=min(A,B)+1
for i in range(K):
  while count!=0:
    count-=1
    if A%count==0 and B%count==0:
      break
else:
  print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#K-th CommonDivisor(B)
a, b, k = map(int, input().split())
if a > b:
    c = b
    d = a
else:
    c = a
    d = b

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def intinput():
    return map(int,input().split())

def gcd(x,y):  #最大公約数
    if x==0:
        return y
    else:
        return gcd(y%x,x)

a,b,k=intinput()
f = gcd(a,b)
x=0
for i in range(f):
    if a%(f-i)==0 and b%(f-i)==0:
        x+=1
        if x==k:
            print(f-i)
            break

Submission status: Accepted

Solution code:
A,B,K=map(int, input().split())
ans=min(A,B)+1
while K:
    ans -= 1
    if (not A%ans and not B%ans):
        K -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

lst = []

val = 1
while val != 101:
    if (A % val == 0) and (B % val == 0):
        lst.append(val)
    val += 1

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

Submission status: Accepted

Solution code:
def main():
    A, B, K = map(int, input().split())
    if A >= B:
        answer(A, B, B, K)
    else:
        answer(A, B, A, K)


def answer(A, B, n, K):
    K_list = []
    for i in range(n, 0, -1):
        if A % i == 0:

            if B % i == 0:
                K_list.append(i)
    print(K_list[K-1])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(list[-K])

Submission status: Accepted

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

cnt = 0
l = []
for i in range(1, a+1 if a > b else 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())
cnt = 0
for i in reversed(range(1,A+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())
m = b if a<b else a
count = 0
cd = []
for i in range(1,m+1) :
	if a%i == 0 and b%i==0 :
		count+=1
		cd.append(i)
cd.sort(reverse=True)
print(cd[k-1])

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
L = 0
ans = 0
for i in reversed(range(1,2000)):
  if A%i == 0:
    if B%i == 0:
      L += 1
    else:
      L += 0
  else:
    L += 0
  if L == K:
    ans = i
    break
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    A, B, K = map(int, input().split())
    v = []
    for i in range(1, 1000):
        if A % i == 0 and B % i == 0:
            v.append(i)
    v = v[::-1]
    print(v[K - 1])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

d = min(A, B)
buf = []
for i in range(d):
    c = d - i
    if A % c == 0 and B % c == 0:
        buf.append(c)
    if len(buf) >= K:
        break
print(buf[-1])

Submission status: Accepted

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

Submission status: Accepted

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


def divisor(a):
    res = set()
    for i in range(1, int(a * 0.5 + 1) + 1):
        if a % i == 0:
            res.add(i)
            res.add(a // i)
    return sorted(res)


a, b, k = map(int, input().split())
ans = divisor(gcd(a, b))[-k]
print(ans)

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

print(i)

Submission status: Accepted

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

a = []
b = []

if A >= 2:
    for i in range(1, A//2):
        if A % i == 0:
            a.append(i)
            a.append(A//i)
else:
    a.append(1)
if B >= 2:
    for i in range(1, B//2):
        if B % i == 0:
            b.append(i)
            b.append(B//i)
else:
    b.append(1)

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

Submission status: Accepted

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

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

print(divisers[-k])

Submission status: Accepted

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

Submission status: Accepted

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

while a>=i and b>=i:
    if a%i==0 and b%i==0:
        list.append(i)
    i+=1

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

Submission status: Accepted

Solution code:
def ls_devider(num):
    fs = set()
    fs.add(1)

    if num > 1:
        for i in range(2, num+1):
            if num % i == 0:
                fs.add(i)

    return fs


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

print(sorted(a_dvs&b_dvs, reverse=True)[k-1])

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

A, B, K = rs()
L = []

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

print(L[-K])