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

k=0
for i in range(max(A,B),0,-1):
    #print(i)
    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())

def solve():
    i = 0
    j = min(a, b)
    while i != k:
        if ((a % j) == 0) and ((b % j) == 0):
            i += 1
        j -= 1
    return j + 1

print(solve())

Submission status: Accepted

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

for x in range(1, 101):
    if a%x==0 and b%x==0:
        lst_ans.append(x)
lst_ans = sorted(lst_ans, reverse=True)
print(lst_ans[(k-1)])

Submission status: Accepted

Solution code:
from sys import stdin
A,B,K=[int(x) for x in stdin.readline().rstrip().split()]
tmp=[]
ans=0
for i in range(1,101):
    if A%i==0 and B%i==0:
        tmp.append(i)
ans=tmp[-K]
print(ans)

Submission status: Accepted

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

li = []

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

print(li[-k])

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
import random
import bisect
#from statistics import mean, median, variance, stdev

#template input

def IT(): #整数1個
    return int(input())
def IL(): #整数複数
    return [int(_) for _ in input().split()]
def IS(): #文字列複数
    return [_ for _ in input().split()]
def ILS(n): #整数1つ　縦にズラーってなってるやつ
    return [int(input()) for _ in range(n)]
def SLS(n): #文字列　縦にズラーってなってるやつ
    return [input() for _ in range(n)]
def ILSS(n): #整数複数　縦にズラーってなってるやつ
    return [[int(_) for _ in input().split()] for j in range(n)]

#template technique
def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)
def bit_full_search2(A):
    #https://blog.rossywhite.com/2018/08/06/bit-search/
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                #output.append(A[j])
                output.append(A[j])
        value.append([format(i, 'b').zfill(16), sum(output)])

    value.sort(key=lambda x:x[1])
    bin = [value[k][0] for k in range(len(value))]
    val = [value[k][1] for k in range(len(value))]
    return bin, val
def matching_bisect(list1_val, list2_val, n):
    #2分探索
    j = 0
    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                #ans = list2_bin[j] + list1_bin[i]
                break
    return j

"""ここからメインコード"""

def main():

    a,b,k = IL()
    c = 0
    for i in range(101, 0, -1):
        if (a)%i == 0 and (b)%i == 0:
            #print(i)
            c += 1
            if c == k:
                print(i)
                break








main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B
a, b, k = map(int, input().split())
l1 = []
l2 = []
for i in range(1,a+1):
    if a % i == 0:
        l1.append(i)

for i in range(1,b+1):
    if b % i == 0:
        l2.append(i)
s1 = set(l1)
s2 = set(l2)
ans = s1 & s2
ans_list = list(ans)
ans_list.sort()
print(ans_list[-k])

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())
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list
      
list_a = make_divisor_list(a) 
list_b = make_divisor_list(b)
a_b = set(list_a) & set(list_b)

print(sorted(list(a_b))[-k])

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

def divisors(n):
    div = []
    A = 1
    while A*A <= n:
        if n%A == 0:
            if A*A == n:
                div += [A]
            else:
                B = n//A
                div += [A, B]
        A += 1
    div.sort()
    return div

g = gcd(A, B)
v = divisors(g)
v.reverse()
print(v[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
A,B,K = map(int,input().split())
ans = []
if A>B:
    Max = A
else:
    Max = B
for i in range(1,Max+1):
    if (A%i==0) & (B%i==0):
        ans.append(i)
print(ans[len(ans)-K])

Submission status: Accepted

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

g=fractions.gcd(a,b)

cd=list()
i=1
while i<=g:
    if g % i == 0:
        cd.append(i)
    i+=1
print (cd[ -1 * k ])

Submission status: Accepted

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

ans = []
maxAnsNum = A
if A > B:
  maxAnsNum = B

for i in range(1,maxAnsNum+1)[::-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())

seq = []

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

print(seq[-k])

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
Aa,Bb,Cc=input().split()
A=int(Aa)
B=int(Bb)
C=int(Cc)
count=0
kazu=min(A,B)
S=[]
for i in range(1,kazu+1):
    if A%i==0 and B%i==0:
        S.append(i)
S.reverse()
print(S[C-1])

Submission status: Accepted

Solution code:
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

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

yakusu = defaultdict(int)

for a in range(A):
    a += 1
    if A % a == 0:
        yakusu[a] += 1
    if B >= a and B % a == 0:
        yakusu[a] += 1

nums = sorted([x for x in yakusu.keys() if yakusu[x] == 2])
print(nums[-(K)])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

cnt = 0

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

Submission status: Accepted

Solution code:
#%%
from fractions import gcd

#%%
a, b, k = map(int, input().split())
g = gcd(a,b)
l = []

for i in range(1,g+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())
ans = []
for i in range(min(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 = list(map(int, input().split()))

cds = []
for i in range(100):
	if a%(i+1)!=0 or b%(i+1)!=0: continue
	cds.append(i+1)

cds.sort()
print(cds[::-1][k-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sei)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
c=max(a,b)
l=[]
for i in range(1,c+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 = tuple(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:
from fractions import gcd
a, b, k = map(int, input().split())
l = gcd(a, b)
lis=[]
for i in range(1,l+1):
  if l%i==0:
    lis.append(i)
print(lis[-k])

Submission status: Accepted

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

Submission status: Accepted

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

list = []
for i in range(1,101):
    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,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())
li = list()
for i in range(1, min(A+1, 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())

k = 0

def judge(x,i):
  return x % i == 0

for i in range(min(A,B),0,-1):
  if judge(A,i) and judge(B,i):
    k += 1
  if k == K:
    break

print(i)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

cnt = 0
ans = -1
for i in range(min(A,B), 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:
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:
A, B, K =map(int, input().split())
A_yaku = []
for i in range(1, int(A/2)+1):
    if A % i == 0:
        A_yaku.append(i)
A_yaku.append(A)
B_yaku = []
for i in range(1, int(B/2)+1):
    if B % i == 0:
        B_yaku.append(i)
B_yaku.append(B)
A_yaku = set(A_yaku)
B_yaku = set(B_yaku)

co_yaku = sorted(list(A_yaku & B_yaku))
for i in range(K):
    tmp = co_yaku.pop(-1)
print(tmp)

Submission status: Accepted

Solution code:
a,b,c = map(int,input().split(" "))
arr1 =[]
arr2 = []

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

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

set_int = set(arr1) & set(arr2)

set_int = list(set_int)
set_int.sort()
print(set_int[-c])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
class Solver:

    def __init__(self):
        pass

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


if __name__ == '__main__':

    solver = Solver()

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

    n = solver.solve(a, b, k)
    print(n)

Submission status: Accepted

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

Submission status: Accepted

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

C=min(A,B)

count = 0

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


a_array = []
b_array = []

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


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


kyou_array = []

for i in a_array:
    if i in b_array:
        kyou_array.append(i)


print(kyou_array[-k])

Submission status: Accepted

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

Submission status: Accepted

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

x = max(A, B)

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

Submission status: Accepted

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

r=[]

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

Submission status: Accepted

Solution code:
import numpy as np

lst=input().split(" ")
A=int(lst[0])
B=int(lst[1])
K=int(lst[2])
lst=[]

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

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

Submission status: Accepted

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

def divisors(n):
  res = []
  for i in range(1, n + 1):
    if n % i == 0:
      res.append(i)

  return res

common = sorted(list(set(divisors(a)) & set(divisors(b))))
print(common[-k])

Submission status: Accepted

Solution code:
# coding: utf-8

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

cnt = 0

mini = min([a, b])
output = 1

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

print(output)

Submission status: Accepted

Solution code:
# 2019/03/03
# AtCoder Beginner Contest 120 - B

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

# Calc
cnt = 0
anslist = list()
for idx in range(1, 101):
    if (a % idx) == 0 and (b % idx) == 0:
        anslist.append(idx)
        cnt += 1

anslist.sort(reverse=True)
# Output
print(anslist[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

m = [x for x in range(1, min(A, B)+1) if A%x==0 and B%x==0]

print(m[-K])

Submission status: Accepted

Solution code:
import fractions
[a,b,k] = [int(i) for i in input().split()]
counter = 0
c = fractions.gcd(a,b)
for i in range(c,0,-1):
    if c % i == 0:
        counter += 1
        #print(i)
    if counter == k:
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def get_gcd(a, b):
  m = max(a, b)
  n = min(a, b)
  while(True):
    if n == 0:
      break
    r = m % n
    m = n
    n = r
  return m


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

gcd = get_gcd(A, B)

cd_list = []
for i in range(1, gcd+1):
  if gcd % i == 0:
    cd_list.append(i)

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

Submission status: Accepted

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

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

print(num_list[-k])

Submission status: Accepted

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

Submission status: Accepted

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

if A > B:
    A, B = B, A
    
if B % A == 0:
    now = 1
    result = A
else:
    now = 0

num = A // 2
while now < K:
    if A % num == 0 and B % num == 0:
        now += 1
        result = num

    num -= 1

print(result)

Submission status: Accepted

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

main()

Submission status: Accepted

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

n=max(A,B)

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

Submission status: Accepted

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

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

wa_list = []

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

print(wa_list[-K])

Submission status: Accepted

Solution code:
import types, math, operator
import numpy as np
from math import sqrt
from collections import Counter
from itertools import product
from functools import reduce
class PrimeUtils:
    @staticmethod
    def _has_numpy():
        g = globals()
        m = g.get('np')
        if m is not None and isinstance(m, types.ModuleType):
            return  m.__name__ == 'numpy'
        return False
    @staticmethod
    def _primes_sieve_pp(n):
        sieve = [True] * (n + 1)
        for i in range(2, int(sqrt(n)) + 1):
            if sieve[i]:
                for j in range(i * i, n + 1, i):
                    sieve[j] = False
        return [i for i, x in enumerate(sieve[2:], 2) if x]
    @staticmethod
    def _primes_sieve_np(n):
        sieve = np.ones(n + 1, np.bool)
        sieve[0] = sieve[1] = False
        for i, v in enumerate(sieve[2:int(sqrt(n)) + 1], 2):
            if v: sieve[i*i::i] = False
        return np.nonzero(sieve)[0]
    @staticmethod
    def _primes_sieve_np_fast(n):
        n += 1
        sieve = np.ones(n//3 + (n%6 == 2), dtype=np.bool)
        check_upper = int(sqrt(n)) // 3
        for i, v in enumerate(sieve[1:check_upper + 1], 1):
            if v:
                k = (3*i + 1) | 1
                sieve[k* k           //3::2*k] = False
                sieve[k*(k-2*(i&1)+4)//3::2*k] = False
        sieve[0] = False
        return np.r_[2,3,((3*np.nonzero(sieve)[0] + 1)|1)]
    @classmethod
    def primes_sieve(cls, n):
        if cls._has_numpy():
            return cls._primes_sieve_np_fast(n)
        else:
            return cls._primes_sieve_pp(n)
    # Prime Factor Decomposition
    @classmethod
    def pfd(cls, n):
        primes = cls.primes_sieve(n)

        factors = []
        cur = n
        for p in primes:
            while True:
                div, rem = divmod(cur, p)
                if rem == 0:
                    factors.append(p)
                    cur = div
                else:
                    break
        assert(cur == 1)
        return factors
    # List up aliquots
    @classmethod
    def aliquots(cls, n):
        pf = cls.pfd(n)
        pfc = Counter(pf)
        ppv = [[pow(p, i) for i in range(n+1)] for p,n in pfc.items()]
        if not ppv:
            return (1,)
        else:
            return map(lambda x: reduce(operator.imul, x), product(*ppv))

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

aa = set(PrimeUtils.aliquots(a))
bb = set(PrimeUtils.aliquots(b))
print(sorted(aa & bb, reverse=True)[k-1])

Submission status: Accepted

Solution code:
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

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

from collections import Counter

a = Counter(a)
b = Counter(b)

s = []
for key in a.keys():
    temp = min(a[key], b[key])
    s += [key] * temp



from itertools import permutations
import numpy as np



def mat(s):
    a = 1
    for ss in s:
        a *= ss
    return a

x = []
for k in range(len(s) + 1):
    for ss in permutations(s, k):
#         print(ss)
        x.append(mat(ss))

x = np.unique(x)
x = np.sort(x)[::-1]

print(x[K - 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def solve():
    A, B, K = map(int, input().split())
    count = 0
    for i in reversed(range(1, A + 1)):
        if A % i == 0 and B % i == 0:
            count += 1
            if count == K:
                ans = i
                break
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
n=min(a,b)
cnt=0
for i in range(n,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 = list(map(int, input().split()))
n = 0
for i in reversed(range(1, max(a, b)+1)):
    if a % i == 0 and b % i == 0:
        n += 1
        #print(i)
        if n == k:
            print(i)
            break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def GCM(p, q):
  if p < q:
    t = p
    p = q
    q = t
  if p % q == 0:
    return q
  else:
    return GCM(q, p%q)
A, B, K = map(int, raw_input().split())
G = GCM(A, B)
i = 1
CM = []
while i*i <= G:
  if G % i == 0:
    CM.append(i)
    CM.append(G/i)
  i += 1
print sorted(list(set(CM)))[-K]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
GCD = gcd(A,B)
count=0
for i in range(GCD,0,-1):
    if GCD // i == GCD/i:
        count +=1
        if count == K:
            ans = i
            break
print(ans)

Submission status: Accepted

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

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

print(D[-K])

Submission status: Accepted

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

Submission status: Accepted

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

print(vv[-1*c])

Submission status: Accepted

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

Submission status: Accepted

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

while count < K:
    x -= 1
    if A % x == 0 and B % x == 0:
        count += 1

print(x)

Submission status: Accepted

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

num = []
for n in range(1, 1+min(a,b)):
    if (a%n) == 0 and (b%n) == 0:
        num.append(n)

#print(num)
print(num[-k])

Submission status: Accepted

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

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

c = gcd(a, b)
cnt = 1
if k == 1:
    print(c)
    exit()
for i in range(2, c):
    if c % i == 0:
        cnt += 1
    if cnt == k:
        print(c // i)
        exit()
print(1)

Submission status: Accepted

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

def func(m,n):
	x = max(m,n)
	y = min(m,n)
	tmp =[]
	for it in range(y):
		it = it + 1
		if x%it == 0 and y%it==0:
			tmp.append(it)
	return tmp

tmp =func(a,b)
print(tmp[len(tmp)-K])

Submission status: Accepted

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

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

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:
b=list(map(int,input().split()))
c=min(b[0],b[1])
k=b[2]
for i in range(c):
    d=c-i
    if b[0]%d==0 and b[1]%d==0:
        k-=1
    if k==0:
        break
print(d)

Submission status: Accepted

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

Submission status: Accepted

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

ds = [int(i) for i in range(1, max(a, b) + 1, 1) if a % i == 0 and b % i == 0]
ds.reverse()
print(ds[k - 1])

Submission status: Accepted

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

def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)
ans = []
for i in range(1,101):
    if gcd(A,B) % i == 0:
        ans.append(i)

print(ans[-K])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding=utf-8


def solve_gcd(number1, number2):
    if number1 == number2:
        return number1

    if number1 < number2:
        number1, number2 = number2, number1

    if number1 % number2 == 0:
        return number2

    return solve_gcd(number2, number1 % number2)


if __name__ == '__main__':
    A, B, K = map(int, input().split())
    gcd = solve_gcd(A, B)
    ctr = 0
    for i in range(gcd, 0, -1):
        if gcd % i == 0:
            ctr += 1
        if ctr == K:
            print(i)
            break

Submission status: Accepted

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

def solv():
    global a, b, k
    n = min(a,b)
    for i in range(n, 0, -1):
        if a%i == 0 and b%i == 0:
            k -= 1
            if k == 0:
                return i

r = solv()
print(r)