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:
def gcd(a, b):
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)


A, B, K = list(map(int, input().split()))
gcd_val = gcd(A, B)
for i in range(gcd_val, 0, -1):
    if gcd_val % i == 0:
        K -= 1
        if K == 0:
            print(i)
            exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
states = list(map(int, input().split()))
counter = 0
i=max(states[0], states[1])

while counter!=states[2]:
    if states[0]%i==0 and states[1]%i==0:
        counter = counter + 1
    i = i-1

print(i+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  5 22:47:49 2019

@author: lab
"""

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

n = min(a,b)
count = 0
while n>0:
    if int(a%n) == 0 and int(b%n) == 0:
        count += 1
        if count == k:
            print(n)
            break
        n -= 1
    else:
        n -= 1

Submission status: Accepted

Solution code:
A,B,K = (int(x) for x in input().split())
i = 1
n = 0
NUM = [0]*min(A,B)

for i in range(1,min(A,B)+1):
    if A%i ==0 and B%i ==0:
        NUM[n] = i
        n+=1
NUM.sort(reverse = 1)

print(NUM[K-1])

Submission status: Accepted

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

check = 0
for i in reversed(range(a)):
  if (a % (i+1)==0) & (b % (i+1)==0):
    check += 1
    if k == check:
      print(i+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sorted(list(set(As) & set(Bs)), key=lambda x: -x)[K-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
C = min(A, B)
nlist = [0]
while 1 <= C:
    if A % C == 0 and B % C == 0:
        nlist.append(C)
    C -= 1
print(nlist[K])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

gcd_res = 0
if a < b:
  gcd_res = gcd(b, a)
else:
  gcd_res = gcd(a, b)

count = 1
for i in reversed(range(1, 101)):
  if (gcd_res % i) == 0:
    if count == k:
      print(i)
      break
    count += 1

Submission status: Accepted

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


w = [0] * K

i = 0
for j in reversed(range(1,max(A,B)+1)):
    if i > K-1 : break
    if A%j == 0 and B%j == 0:
        w[i] = j
        i += 1
        
        

print(w[K-1])

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math
A,B,K = map(int,input().split())
Alist = []
Blist = []
ab = max(A,B)
for a in range(1,ab+1):
    aa = A%a
    ba = B%a
    if aa == 0:
        Alist.append(a)
    if ba == 0:
        Blist.append(a)
AB = sorted(set(Alist) & set(Blist))
z = len(AB)
print(AB[z-K])

Submission status: Accepted

Solution code:
A,B,K = list(map(int,input().split()))
def solve(A,B,K):
    k = 1
    for i in reversed(range(1,max(B+1,A+1))):
        if A%i == 0 and B%i == 0:
            if K == k:
                return i
            else:
                k = k + 1
print(solve(A,B,K))

Submission status: Accepted

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

Submission status: Accepted

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

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

num = nums[-K]
print(num)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
tmp = list(map(int, input().split()))
A, B, K= tmp[0], tmp[1], tmp[2]

i, j = A, B
if A > B:
  i, j = B, A

for k in reversed(range(i)):
  tmp = k + 1
  if i % tmp == 0 and j % tmp == 0:
    K -= 1
  if K == 0:
    print(tmp)
    break

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

Submission status: Accepted

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


cnt = 0

for i in reversed(range(1,min(A,B)+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())
cd = []

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c = 0

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
i=0
count=0
while True:
    a,b=max(a,b)%min(a,b),min(a,b)
    if a==0:
        break
while count<c:
    i+=1
    if b%i==0:
        count+=1
print(b//i)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A,B,K = map(int, raw_input().split())
num = 1                                                                                                             
ans = []
while(num <= 100):
    if A%num == 0 and B%num == 0:
        ans.append(num)
    num += 1
print ans[-K]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    A, B, K = map(int, input().split())
    CDD = []
    maxi = max(A,B)
    mini = min(A,B)
    for i in reversed(range(1, mini + 1)):
        if mini % i == 0:
            if maxi % i == 0:
                CDD.append(i)
    print(CDD[K - 1])
main()

Submission status: Accepted

Solution code:
def kth_common_divisor(a, b, k):
    min_ = min(a, b)
    divisors = []

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

    return divisors[-k]


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

Submission status: Accepted

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

count = 0
i = 1
list = []

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

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

Submission status: Accepted

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

ans_list=[]

maximum=max(A,B)

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

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

Submission status: Accepted

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

def maxDivider(divider, divided):
    while(True):
        rest = divided % divider
        if rest == 0:
            return divider
        else:
            divided = divider
            divider = rest

def dividers(x):
    dividers = []
    divider = 1
    while(divider <= x / divider):
        if x % divider == 0:
            dividers.append(divider)
            if divider == int(x / divider):
                pass
            else:
                dividers.append(int(x / divider))
        else:
            pass
        divider += 1
    return sorted(dividers)

# set A <= B
if A > B:
    A, B = B, A
else:
    pass

ans = dividers(maxDivider(A, B))[-K]
print(ans)

Submission status: Accepted

Solution code:
def main():

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

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


main()

Submission status: Accepted

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

Submission status: Accepted

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

AB=[A,B]
L=[]

for n in range(1,min(AB)+1):
  if (A%n==0)&(B%n==0):
    L.append(n)

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

Submission status: Accepted

Solution code:
a, b, k = map(int,input().split())
div = min(a,b)
cnt = 0
for i in reversed(range(1,div+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())

l = []

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - K-th Common Divisor
https://atcoder.jp/contests/abc120/tasks/abc120_b

"""
import sys


def solve(A, B, K):
    divisors = []
    for i in range(1, A+1):
        if A % i == 0 and B % i == 0:
            divisors.append(i)
    return divisors[-K]


def main(args):
    A, B, K = map(int, input().split())
    ans = solve(A, B, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(d)

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
divisor_A = [A] 
divisor_A_count = 2 
divisor_B = [B]
divisor_B_count = 2
for i in range(A-1,1,-1):
    if (A % i) == 0:
        divisor_A.append(i)
        divisor_A_count += 1
divisor_A.append(1) 
for i in range(B-1,1,-1):
    if (B % i) == 0:
        divisor_B.append(i)
        divisor_B_count += 1
divisor_B.append(1) 
a_num = 1   
a = divisor_A[a_num-1]   
b_num = 1   
b = divisor_B[b_num-1]   
c_divisor_count = 0  
for i in range(divisor_A_count * divisor_B_count):
    
    if divisor_A[a_num-1] == divisor_B[b_num-1]:
        c_divisor_count += 1
        if c_divisor_count == K:
            break
        else:
            a_num += 1
            b_num += 1
    
    elif divisor_A[a_num-1] > divisor_B[b_num-1]:
        a_num += 1
    else: 
        b_num += 1
print(divisor_A[a_num-1])

Submission status: Accepted

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

Submission status: Accepted

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

    list =[]
    for i in range(D+1):
        if i!=0:
            if (A%i == 0) & (B%i == 0) :
                list.append(i)
    print(list[(len(list)-C)])
    


main()

Submission status: Accepted

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

max_num = min(a, b)
cnt = 0
for n in range(max_num, 0, -1):
    if (a % n) + (b % n):
        continue
    cnt += 1
    if cnt == k:
        print(n)
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc120/tasks/abc120_b


def calc(a, b, k):
    ans = 0
    hit = 0
    for i in range(max(a, b), 0, -1):
        if a % i == 0 and b % i == 0:
            hit += 1
            if hit == k:
                ans = i
                break
    return ans


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

print(calc(a, b, k))

Submission status: Accepted

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

for i in range(max_AB):
    if A % (i + 1) == 0 and B % (i + 1) == 0:
        l.append(i+1)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
ABK = [int(i) for i in input().split()]
answer = 0
count = 0
num_list = [i for i in range(1,101)]
index = 0
while(count != ABK[2]):
    index -= 1
    if(ABK[0] % num_list[index] == 0 and ABK[1] % num_list[index] == 0):
        count += 1

print(num_list[index])

Submission status: Accepted

Solution code:
from sys import stdin

# 標準入力の受取
# sdi = stdin.readline().rstrip()
# a, b, c = stdin.readline().rstrip().split()
# a, b, c = [x for x in stdin.readline().rstrip().split()]
a, b, c = [int(x) for x in stdin.readline().rstrip().split()]
i = max(a, b)
answer = 0
hit = 0
while 1:
    if a % i == 0 and b % i == 0:
        r = i
        hit += 1
    if hit == c:
        break
    i -= 1

print(r)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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,s,d=map(int,input().split())
l=[]
for i in range(1,min(a,s)+1):
  if a%i==0 and s%i==0:
    l.append(i)
print(l[-d])

Submission status: Accepted

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

Submission status: Accepted

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

CD = []
for i in range(1, min(x[0], x[1])+1):
    if x[0] % i == 0 and x[1] % i == 0:
        CD.append(i)
    else:
        continue

print(CD[-x[2]])

Submission status: Accepted

Solution code:
def is_divisible_A_and_B(x, A, B):
    if A % x == 0 and B % x == 0:
        return True
    else:
        return False

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

k = min(A, B)
divisible_list = []
for i in range(1, k + 1):
    if is_divisible_A_and_B(i, A, B):
        divisible_list.append(i)

print(divisible_list[-K])

Submission status: Accepted

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

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

print(list[-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 k == count:
      print(i)
      break

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    lowerNum = A
    if A > B :
        lowerNum = B

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,min_n+1):
  if A%i == 0 and B%i == 0:
    gcd_.append(i)
gcd_.sort(reverse=True)
print(gcd_[K-1])

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split(' '))
# 与えられた整数の約数を返す
def func_divisors(x):
  divisors = []
  for i in range(1,int(x**0.5)+1):
    if x % i == 0:
      divisors.append(i)
      if i != x / i:
        divisors.append(int(x/i))
        
  divisors.sort()
  return divisors
  
A_divisors = func_divisors(A)
B_divisors = func_divisors(B)
C_divisors = sorted(list(set(A_divisors) & set(B_divisors)),reverse=True)

print(C_divisors[K-1])

Submission status: Accepted

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

def main():
    cnt = 0
    for x in range(min(A, B), 0, -1):
        if A%x==0 and B%x==0:
            cnt += 1
            if cnt == K:
                print(x)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

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

m=min(A,B)
c=0
for i in range(0,m):
	j=m-i
	#print(j,c)
	if(A%j==0 and B%j==0):
		c+=1
	if(c==K):
		print(j)
		exit()

Submission status: Accepted

Solution code:
import sys

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return a


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


j=0
for i in range(gcd,0,-1):
    if gcd%i==0:
        j+=1
    if j==k:
        print(i)
        sys.exit()

Submission status: Accepted

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

if(a>=b):
    min = b
else:
    min = a


list = []

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

print(list[c-1])

Submission status: Accepted

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

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

print(j)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for i in range(101,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:
# Euclidean Algorithm
def gdc(m, n):
    m, n = (m, n) if m > n else (n, m)
    while True:
        if n == 0:
            break
        else:
            m, n = n, m % n
    return m


A, B, K = [int(x) for x in input().split(" ")]
divisor = [x for x in list(range(1, gdc(A, B)+1)) if gdc(A, B) % x == 0]

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

Submission status: Accepted

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

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

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

if ans:
    print(ans[-k])
else:
    print("1")

Submission status: Accepted

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

a,b,k = map(int,input().split())
acd = []
bcd = []
cd = []

for i in range(1,a+1):
    if a % i == 0:
        acd.append(i)
for i in range(1,b+1):
    if b % i == 0:
        bcd.append(i)
for i in acd:
    for j in bcd:
        if i == j:
            cd.append(i)
print(cd[-k])

Submission status: Accepted

Solution code:
a,b,k = list(map(int,input().split()))
c= 1
d=0
if b < a:
    a,b=b,a
while True:
    d = b%a
    if d == 0:
        c=a
        break
    else:
        b = a
        a = d
e = 0
for i in range(1,c+1):
    if c%i == 0:
        e +=1
        if e == k:
            print(int(c/i))
            break

Submission status: Accepted

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

Submission status: Accepted

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


abk = list(map(int, input().split()))
a = abk[0]
b = abk[1]
k = abk[2]
ab_gcd = gcd(a, b)
ab_div = []
for i in range(ab_gcd):
    if ab_gcd % (i + 1) == 0:
        ab_div.append(i + 1)
print(ab_div[-k])

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
N = 0
i = 101
while N != K:
    i -= 1
    if A % i == 0 and B % i == 0:
        N += 1
#        print(i,N,K)
print(i)

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
count = 0
for_max = max([A, B])

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

Submission status: Accepted

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

if a > b:
    for i in range(b):
        if a % (i+1) == 0 and b % (i+1) == 0:
            kazu.append(i+1)
else:
    for i in range(a):
        if a % (i+1) == 0 and b % (i+1) == 0:
            kazu.append(i+1)

print(kazu[-k])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""B - K-th Common Divisor"""
A,B,K=(int(i) for i in input().split())
result=[]
for i in range(1,min(A,B)+1):
  if A%i==0 and B%i==0:
    result.append(i)
result.reverse()
print(result[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num1, num2, target = [int(i) for i in input().split()]

smaller = min([num1, num2])


common_div_num = 0
for i in reversed(range(1, smaller + 1)):
    if num1 % i == 0 and num2 % i == 0:
        common_div_num += 1
        if common_div_num == target:
            break


print(i)

Submission status: Accepted

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

Submission status: Accepted

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


#2番目に大きいもの

Submission status: Accepted

Solution code:
from sys import stdin
import fractions

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

num_list = []

for i in range(1, fractions.gcd(A,B)+1):
    if A % i == 0 and B % i == 0:
        num_list.append(i)

print(num_list[-(K)])

Submission status: Accepted

Solution code:
from sys import stdin

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


num_list = []

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

print(num_list[-(K)])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

kk = 0
out = 0

for i in range(min(a,b),0,-1):
    aa = a % i
    bb = b % i
    
    if (aa+bb)==0:
        kk += 1
        #print(aa,bb,i)
        if kk==k:
            out = i
            break
print(out)