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:
a, b ,k =map(int, input().split())

l = []
for i in range(1,max(a,b)+1):
    if max(a,b)%i == 0:
        l.append(i)
m = []
for j in range(1,min(a,b)+1):
    if min(a,b)%j == 0:
        m.append(j)
z = []
for n in l:
    for o in m:
        if n == o:
            z.append(o)
print(z[-k])

Submission status: Accepted

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

l = []
for i in range(1,max(a,b)+1):
    if max(a,b)%i == 0:
        l.append(i)
m = []
for j in range(1,min(a,b)+1):
    if min(a,b)%j == 0:
        m.append(j)
z = []
for n in l:
    for o in m:
        if n == o:
            z.append(o)
#print(l)
#print(m)
#print(z)
print(z[-k])

Submission status: Accepted

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

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

print(ans[-k])

Submission status: Accepted

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


dList = []
i = 0 
while True :
  i += 1
  if a % i == 0 and b % i == 0:
    dList.append(i)
  if i >= a or i >= b:
    break

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

Submission status: Accepted

Solution code:
def main(a, b, k):
    t = []
    _max = max(a, b)

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

    print(t[-k])


if __name__ == "__main__":
    a, b, k = map(int, input().split())

    main(a, b, k)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(divisor[-K])

Submission status: Accepted

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

divisor = []

for i in range(min(A,B)+1):
    if i == 0:
        continue

    if A % i == 0 and B % i == 0:
        divisor.append(i)

print(divisor[::-1][K-1])

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)

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A, B, K = map(int, readline().split())
lis=[]
for i in range(1, min(A, B) + 1):

    if A % i == 0 and B % i == 0:
        lis.append(i)
lis.reverse()
print(lis[K-1])

Submission status: Accepted

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

ans = []

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

print(ans[-K])

Submission status: Accepted

Solution code:
import sys
from math import sqrt, floor

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

a, b, k = map(int, sys.stdin.readline().split())

def main():
    g = gcd(a, b)
    cand = set()
    for i in range(1, floor(sqrt(g)) + 1):
        if not g % i:
            cand.add(i)
            cand.add(g // i)

    return sorted(cand)[-k]

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

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

a,b,k = map(int,input().split())
aa = make_divisors(a)
bb = make_divisors(b)
print(sorted(set(aa) & set(bb))[-k])

Submission status: Accepted

Solution code:
def koyaku(A, B):
    ans = []
    for i in range(1,A+1):
        if A%i == 0 and B%i == 0:
            ans.append(i)    
    return ans
if __name__ == "__main__":
    A, B, K = map(int, input().split())
    if B > A:
        tmp = A
        A = B
        B = tmp
    ans = koyaku(A, B)
    print(ans[-K])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

C = min(A,B)
num = 0
ans = []
for i in range(1,C+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=map(int,input().split())
l=[]

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

Submission status: Accepted

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

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

# print(common_divisors)
print(common_divisors[-K])

Submission status: Accepted

Solution code:
a,b,k = map(int,input().split())
class stack:
    def __init__(self):
       self.items = []
        
    def is_empty(self):
       return self.items == []
        
    def push(self, item):
       self.items.append(item)
        
    def pop(self):
       return self.items.pop()
        
    def peek(self):
       return self.items[len(self.items)-1]
        
    def size(self):
       return len(self.items)

ansstack = stack()
for i in range(1, max(a, b) + 1):
    if a % i == 0 and b % i == 0:
        ansstack.push(i)
ans = 0
for i in range(k):
    ans = ansstack.pop()
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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()
print(ans[len(ans) - k])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

max_num = max(A, B)
min_num = min(A, B)
divs = [m for m in range(1, min_num+1) if min_num % m == 0]

ans = []
for d in divs:
    if max_num % d == 0:
        ans.append(d)
ans = sorted(ans)[::-1]
print(ans[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
c=min(a,b)
cnt=0
for i in range(c,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())
R = [1]
for s in range(2,min(A,B)+1):
    if B % s == 0 and A % s == 0:
            R.append(s)
print(R[-K])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
A, B, K = map(int, input().split())

if A > B :
  tmp = A
  A = B
  B = tmp

ki = 0
for i in range(A) :
  n = A-i
  if A%n == 0 and B%n == 0 :
    ki += 1
    if ki == K :
      print (n)

Submission status: Accepted

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

res = []

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

Submission status: Accepted

Solution code:
A,B,C = list(map(int,input().split(" ")))
min_number = min(A,B)
listA = []
for i in range(1,min_number+1):
    if A % i == 0 and B % i == 0:
        listA.append(i)
listA.sort(reverse=True)
print(listA[C-1])

Submission status: Accepted

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

  
print(c)

Submission status: Accepted

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


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


S = sorted(list(set(divisor(A)) & set(divisor(B))), reverse=True)
print(S[K - 1])

Submission status: Accepted

Solution code:
a,b,k = map(int, input().split())
a_div = {i for i in range(1,a+1) if a%i == 0}
b_div = {i for i in range(1,b+1) if b%i == 0}
sorted_div = sorted(list(a_div & b_div), reverse=True)
print(sorted_div[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
li=list(map(int,input().split()))
a=[]
for i in range(1,min(li[0],li[1])+1):
    if li[0]%i==0 and li[1]%i==0:
        a.append(i)
print(a[len(a)-1-li[2]+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 or B % i:
        continue
    if K == 1:
        print(i)
        break
    K -= 1

Submission status: Accepted

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

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

print(k_list[-k])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, N = map(int, 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 == N:
            print(i)

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

Submission status: Accepted

Solution code:
import sys
bbn=1000000007
	
#+++++
		
def main():
	a, b , k = map(int, input().split())
	c=0
	ll=[]
	for i in range(1,200):
		if a% i==0 and b%i==0:
			ll.append(i)
	return ll[-1*k]
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

for i in range(1, A + 1):
    if A % i == 0:
        s1.add(i)

for j in range(1, B + 1):
    if B % j == 0:
        s2.add(j)

lst = sorted(list(s1 & s2), reverse=True)

print(lst[K-1])

Submission status: Accepted

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

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

else:
    lst.append(1)

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

Submission status: Accepted

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

Submission status: Accepted

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

divided = []

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

print(divided[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

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=map(int,input().split())
cnt=0
for i in range(min(A,B),0,-1):
    if A%i==B%i==0:
        cnt+=1
    if cnt==K:
        print(i)
        break

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353



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

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

Submission status: Accepted

Solution code:
A, = [list(map(int, s.split())) for s in open(0)]
x, y = min(A[:2]), max(A[:2])
cds = []
for i in range(1, x + 1):
    if (x % i == 0) and (y % i == 0):
        cds.append(i)

print(sorted(cds, reverse=True)[A[2]-1])

Submission status: Accepted

Solution code:
N = list(map(int,input().split()))
def cf(x1,x2):
    cf=[]
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf
ans = cf(N[0],N[1])
print(ans[-N[2]])

Submission status: Accepted

Solution code:
from fractions import gcd
a,b,k=map(int,input().split())
c=gcd(a,b)
t=[c]
while(c>1):
  c=c-1
  if(a%c==0 and b%c==0):
    t.append(c)
print(t[k-1])

Submission status: Accepted

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

a,b,k = map(int,input().split())
g = gcd(a,b)
cnt = 1

while cnt != k:
    g -= 1
    if a%g == 0 and b%g == 0:
        cnt += 1
else:
    ans = g

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

Submission status: Accepted

Solution code:
def solve():
    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)
                exit()


if __name__ == '__main__':
    solve()

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

Submission status: Accepted

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

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

ans = cf(A, B)
ans.sort(reverse=True)

print(ans[K-1])

Submission status: Accepted

Solution code:
import math
a, b, k = map(int, input().split())
lst_max_num = []
lst_both = []
max_num = max(a, b)
min_num = min(a, b)
n = int(math.sqrt(max_num))
for i in range(1, n + 1):
    if max_num % i == 0 and max_num // i != i:
        lst_max_num.append(i)
        lst_max_num.append(max_num // i)
    elif max_num % i == 0 and max_num // i == i:
        lst_max_num.append(i)

for i in lst_max_num:
    if  min_num % i == 0:
        lst_both.append(i)

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

Submission status: Accepted

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

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

ans = list()
for i in range(1, max(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=map(int,input().split())
lis=[]
for i in range(1,min(a,b)+1):
  if a%i==0 and b%i==0:
    lis.append(i)
lis.sort(reverse=True)
print(lis[k-1])

Submission status: Accepted

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

cnt = 0

i = min(a,b)
for x in range(min(a,b)):
    
    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())
kth = 0
for i in range( min(a, b), 0, -1 ):
    if a % i == 0 and b % i == 0:
        kth += 1
    if kth == k:
        ans = i
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
ans=[]
def gcd(a,b):
    if b>a:
        return(gcd(b,a))
    elif b==0:
        return a
    else:
        return(gcd(b,a%b))
g=gcd(a,b)
for i in range(1,g+1):
    if g%i==0:
        ans.append(i)
print(ans[-k])

Submission status: Accepted

Solution code:


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

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  return set(table)

ad=divisor(a)
bd=divisor(b)

abd = list(set(ad & bd))
abd.sort()

print(abd[-k])

Submission status: Accepted

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

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

    # divisors.sort()
    return divisors

C=make_divisors(gcd(a,b))
C.sort()
#print(C)
print(C[-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, kth = map(int, input().split())
count = 0
for div in range(min(a, b), 0, -1):
    if a % div == 0 and b % div == 0:
        count += 1
        if count == kth:
            print(div)
            exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(s[-k])

Submission status: Accepted

Solution code:
a, b, k = [int(i) for i in 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:
import os, sys, re, math

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def common_divisor(a, b):
  ans = []
  mn = min(a, b)
  mx = max(a, b)
  for i in range(1, min(a, b) + 1):
    if a % i == 0 and b % i == 0 :
      ans.append(i)
  
  return ans

a, b, c = [int(x) for x in input().split()]
kys = common_divisor(a, b)
print(kys[len(kys) - c])

Submission status: Accepted

Solution code:
a, b, n = map(int, input().split())
alis = [x for x in range(1, a + 1) if a % x == 0]
blis = [x for x in range(1, b + 1) if b % x == 0]
lis = list(set(alis) & set(blis))
print(sorted(lis,reverse=True)[n - 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import fractions
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

A, B, K = [int(x) for x in readline().rstrip().split()]
gcd_ = fractions.gcd(A, B)


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
print(make_divisors(gcd_)[-K])

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
def gcd(a, b):
  if a % b == 0:
    return b
  else:
    return gcd(b, a % b)

g = gcd(a, b)
n = 0
for i in range(g, 0, -1):
  if g % i == 0:
    n += 1
  if n == k:
    print(i)
    quit()

Submission status: Accepted

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

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

    # divisors.sort()
    return divisors

list_a = make_divisors(a)
list_b = make_divisors(b)
common = list(set(list_a) & set(list_b))
common.sort()
print(common[-k])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(i)

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]) #iに0含めるとゼロ割

Submission status: Accepted

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

Submission status: Accepted

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

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

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())
z=min(a,b)
n=0
while(z>=1):

    if(a%z==0 and b%z==0):
        n+=1;
        if n==k:
            break
    z-=1

print(z)

Submission status: Accepted

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

print(c[-k])

Submission status: Accepted

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def divisor(n):
    """
    n の約数をリストで返す
    :param int n:
    :rtype: list of int
    """
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret

def MI(): return map(int, input().split())


def main():
    A, B, K = MI()
    common = []
    a = divisor(A)
    b = divisor(B)

    for i in range(len(a)):
        if a[i] in b:
            common.append(a[i])

    common.sort()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

div_list = []

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

print(div_list[-K])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, k = map(int, input().split())
la = [x for x in range(1, a + 1) if a % x == 0]
lb = [x for x in range(1, b + 1) if b % x == 0]
l = set(la) & set(lb)
n = sorted(l, reverse=True)
print(list(n)[k - 1])

Submission status: Accepted

Solution code:
import math

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

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

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



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(A, B, K):
    """Test Case
    >>> print_ans(8, 12, 2)
    2
    >>> print_ans(100, 50, 4)
    5
    >>> print_ans(1, 1, 1)
    1
    """
    counter = 0
    for i in range(1, min(A, B) + 1)[::-1]:
        if A % i == 0 and B % i == 0:
            counter += 1
        if counter == K:
            print(i)
            break


if __name__ == '__main__':
    A, B, K = map(int, input().rstrip().split())
    print_ans(A, B, K)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

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

Submission status: Accepted

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

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

Submission status: Accepted

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