AtCoder Beginner Contest 120 - K-th Common Divisor

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-----
8 12 2

-----Sample Output-----
2

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

Difficulty: EASY

Starter code:

Solutions:
(a, b, k) = map(int, input().split())
i = 0
l = []
while i < min(a, b) + 1:
	i += 1
	if a % i == 0 and b % i == 0:
		l.append(i)
print(l[-k])


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


(A, B, K) = map(int, input().split())
H = []
i = 1
while i <= min(A, B):
	if A % i == 0 and B % i == 0:
		H.append(i)
	i += 1
print(H[-K])


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


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


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


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


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


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


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


(A, B, K) = list(map(int, input().split()))
for x in range(100, 0, -1):
	if A % x == 0 and B % x == 0:
		K -= 1
	if K == 0:
		print(x)
		break


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


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


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


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


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


(A, B, K) = list(map(int, input().split()))
ans = 0
n = 100
while True:
	if A % n == 0 and B % n == 0:
		ans += 1
		if ans == K:
			print(n)
			return
	n -= 1


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


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


(a, b, k) = map(int, input().split())
i = a
r = 0
while True:
	if a % i == 0 and b % i == 0:
		r += 1
	if k == r:
		break
	i -= 1
print(i)


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


(n, m, k) = map(int, input().split())
for i in range(min(n, m), 0, -1):
	if n % i == 0 and m % i == 0:
		k -= 1
		if k == 0:
			print(i)
			exit()


from typing import Set

def divisors(n: int) -> Set[int]:
	divs = set()
	i = 1
	while i * i <= n:
		if n % i == 0:
			divs.add(i)
			divs.add(n // i)
		i += 1
	return divs

def answer(a: int, b: int, k: int) -> int:
	divisors_a = divisors(a)
	divisors_b = divisors(b)
	common_divisors = list(divisors_a & divisors_b)
	common_divisors.sort()
	return common_divisors[-k]

def main():
	(a, b, k) = list(map(int, input().split()))
	print(answer(a, b, k))

def __starting_point():
	main()
__starting_point()


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


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


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

def gcd(a, b):
	while b > 0:
		temp = a % b
		a = b
		b = temp
	return a
C = gcd(A, B)
i = C + 1
while K > 0:
	i -= 1
	if C % i == 0:
		K -= 1
print(i)


(a, b, k) = map(int, input().split())
c = 0
p = min(a, b)
while c != k:
	if a % p == 0 and b % p == 0:
		x = p
		c += 1
	p -= 1
print(x)


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


import math
(a, b, k) = map(int, input().split())
c = math.gcd(a, b)
d = [i for i in range(1, c + 1) if c % i == 0]
print(d[-k])


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

def __starting_point():
	main()
__starting_point()


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


(A, B, K) = [int(x) for x in input().split(' ')]
n = [i for i in range(1, min(A, B) + 1) if A % i == 0 and B % i == 0]
print(n[-K])


import io
(n, m, k) = map(int, input().split())
data = n
while k:
	if n % data == m % data == 0:
		k -= 1
	data -= 1
print(data + 1)


(a, b, k) = map(int, input().split())
L = []
n = a
if a < b:
	n = b
for i in range(n):
	if a % (i + 1) == 0 and b % (i + 1) == 0:
		L.append(i + 1)
L = sorted(L, reverse=True)
print(L[k - 1])


import math
(num1, num2, target) = list(map(int, input().split()))
number = math.gcd(num1, num2)
table = []
for j in range(1, number + 1):
	if number % j == 0:
		table.append(j)
list.sort(table, reverse=True)
print(table[target - 1])


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


(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)
e = d[::-1]
print(int(e[k - 1]))


(A, B, K) = map(int, input().split())
n = A
while K:
	if A % n == B % n == 0:
		K -= 1
	n -= 1
print(n + 1)


(A, B, K) = map(int, input().split())
ans = [n for n in range(A, 0, -1) if A % n == B % n == 0][K - 1]
print(ans)


(A, B, K) = map(int, input().split())
List = [x for x in range(min(A, B), 0, -1) if A % x == 0 and B % x == 0]
print(List[K - 1])


(A, B, K) = map(int, input().split())
lst = []
for n in range(1, min(A, B) + 1):
	if B % n == 0:
		lst.append(n)
lst2 = []
for m in lst:
	if A % m == 0:
		lst2.append(m)
print(sorted(lst2, reverse=True)[K - 1])


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


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


(a, b, k) = map(int, input().split())
print(list(filter(lambda x: a % x + b % x == 0, [i for i in range(min(a, b), 0, -1)]))[k - 1])


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


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


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


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


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


(a, b, k) = map(int, input().split())
t = min(a, b)
while k > 0:
	if a % t == 0 and b % t == 0:
		k -= 1
	t -= 1
print(t + 1)


(int1, int2, rank) = map(int, input().split())
kouyaku_list = []
for i in range(1, 100 + 1):
	if int1 % i == 0 and int2 % i == 0:
		kouyaku_list.append(i)
print(kouyaku_list[-rank])


(a, b, k) = list(map(int, input().split()))
result = [i for i in range(1, 101) if a % i == b % i == 0]
print(result[-k])


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


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


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


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

def ans120(A: int, B: int, K: int):
	l = sorted([A, B])
	ans_list = []
	for i in range(1, l[1] + 1):
		if A % i == 0 and B % i == 0:
			ans_list.append(i)
	return ans_list[-K]
print(ans120(A, B, K))


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


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


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


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

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


def __starting_point():
	(A, B, K) = list(map(int, input().split()))
	a_ans = []
	b_ans = []
	for a in range(1, A + 1):
		if A % a == 0:
			a_ans.append(a)
	for b in range(1, B + 1):
		if B % b == 0:
			b_ans.append(b)
	ans = list(set(a_ans) & set(b_ans))
	ans.sort(reverse=True)
	print(ans[K - 1])
__starting_point()


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

def ans120(A: int, B: int, K: int):
	if A >= B:
		n = A
	else:
		n = B
	ans_list = []
	for i in range(1, n + 1):
		if A % i == 0 and B % i == 0:
			ans_list.append(i)
	return ans_list[-K]
print(ans120(A, B, K))


(A, B, K) = [int(i) for i in input().split()]
print([i for i in range(max(A, B), 0, -1) if A % i == 0 and B % i == 0][K - 1])


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


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


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


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


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


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


(a, b, c) = map(int, input().split())
n = a
while c:
	if a % n == b % n == 0:
		c -= 1
	n -= 1
print(n + 1)


(a, b, k) = map(int, input().split())
count = 0
n = min(a, b)
for i in reversed(range(1, n + 1)):
	if a % i == 0 and b % i == 0:
		count += 1
		if count == k:
			ans = i
print(ans)


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

def cf(a, b):
	for i in range(2, min(a, b) + 1):
		if a % i == 0 and b % i == 0:
			li.append(i)
	return li
cf(a, b)
li.insert(0, 1)
li.reverse()
print(li[k - 1])


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


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


(A, B, K) = list(map(int, input().split()))
divid_number = []
for X in range(1, 100 + 1):
	if A % X == 0 and B % X == 0:
		divid_number.append(X)
divid_number.reverse()
print(divid_number[K - 1])


(a, b, k) = map(int, input().split())
i = min(a, b) + 1
while k:
	i -= 1
	if max(a % i, b % i) == 0:
		k -= 1
print(i)


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


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


(A, B, K) = map(int, input().split())
l = [i for i in range(100, 0, -1) if (A % i == 0) & (B % i == 0)]
print(l[K - 1])


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


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


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
(A, B, K) = map(int, input().split(' '))
a_divisor = divisor(A)
b_divisor = divisor(B)
print(sorted(list(set(a_divisor) & set(b_divisor)), reverse=True)[K - 1])


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


(A, B, K) = map(int, input().split())
c = 0
if A < B:
	R = A
else:
	R = B
for i in range(R):
	I = R - i
	if A % I == 0 and B % I == 0:
		c += 1
		if c == K:
			print(I)
			break


import sys
input = sys.stdin.readline

def main():
	(A, B, K) = [int(x) for x in input().split()]
	yakusu = []
	for i in range(1, 101):
		if A % i == 0 and B % i == 0:
			yakusu.append(i)
	print(sorted(yakusu, reverse=True)[K - 1])

def __starting_point():
	main()
__starting_point()


(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
div_A = make_divisors(A)
div_B = make_divisors(B)
l = []
for i in div_A:
	for j in div_B:
		if i == j:
			l.append(i)
print(l[-K])


(A, B, K) = map(int, input().split())
count = 0
wari = min(A, B)
while True:
	if A % wari == 0 and B % wari == 0:
		count += 1
	if count == K:
		print(wari)
		return
	wari -= 1


[a, b, k] = map(int, input().split())
res = [i for i in range(1, max(a, b) + 1) if a % i == 0 and b % i == 0]
print(sorted(res, reverse=True)[k - 1])


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


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


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


def make_divisors(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
(a, b, k) = list(map(int, input().split()))
import math
print(make_divisors(math.gcd(a, b))[-k])


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


[A, B, K] = list(map(int, input().split()))
L = []
for i in range(1, 101):
	if A % i + B % i == 0:
		L.append(i)
print(L[-1 * K])


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

def answer(a: int, b: int, k: int) -> int:
	result = []
	if a > b:
		for i in range(1, b + 1):
			if a % i == 0 and b % i == 0:
				result.append(i)
		return result[len(result) - k]
	else:
		for i in range(1, a + 1):
			if a % i == 0 and b % i == 0:
				result.append(i)
		return result[len(result) - k]
print(answer(a, b, k))


(A, B, K) = map(int, input().split())
res = [i for i in range(1, 200) if A % i == 0 and B % i == 0]
print(res[-K])


(a, b, c) = map(int, input().split())
lis = list(range(1, min(a, b) + 1))
lis = [x for x in lis if a % x == 0 and b % x == 0]
print(lis[-c])


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


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


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


def input2():
	return map(int, input().split())
(a, b, k) = input2()
MAX = max(a, b)
count = 0
ans = 0
for i in range(MAX, 0, -1):
	if a % i == 0 and b % i == 0:
		count += 1
		if count == k:
			print(i)
			break


(a, b, k) = map(int, input().split())
ans = []
i = 0
while i < 101:
	i += 1
	if a % i == 0 and b % i == 0:
		ans.append(i)
print(ans[-k])


(a, b, k) = map(int, input().split())
l = [i for i in range(1, min(a, b) + 1) if not (a % i or b % i)]
print(l[-k])


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


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


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


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


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


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


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


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


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


(A, B, K) = map(int, input().split())
(i, t) = (101, 1)
while t <= K:
	i -= 1
	if A % i == 0 and B % i == 0:
		t += 1
print(i)


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


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


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

def divisor(n, m):
	if n > m:
		(n, m) = (m, n)
	for i in range(1, m + 1):
		if n % i == 0 and m % i == 0:
			lst.append(i)
	lst.reverse()
	print(lst[K - 1])
divisor(A, B)


(A, B, K) = list(map(int, input().split()))
ans = []
for a in range(1, A + 1):
	if A % a == 0 and B % a == 0:
		ans.append(a)
print(ans[-K])


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


(A, B, K) = list(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
div_A = make_divisors(A)
div_B = make_divisors(B)
print(sorted(set(div_A) & set(div_B))[-K])


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
(a, b, k) = list(map(int, input().split()))
table = []
divisor_a = divisor(a)
divisor_b = divisor(b)
for i in divisor_a:
	if i in divisor_b:
		table.append(i)
table.sort(reverse=True)
print(table[k - 1])


def atc_120b(ABK: str) -> int:
	(a, b, k) = map(int, ABK.split(' '))
	result_value = min(a, b)
	letter_count = 0
	for i in range(result_value, 0, -1):
		if a % i == 0 and b % i == 0:
			letter_count += 1
		if letter_count == k:
			break
	return i
ABK_input = input()
print(atc_120b(ABK_input))


(a, b, k) = [int(x) for x in input().split()]
(a_list, b_list) = ([], [])
for ai in range(1, a + 1):
	if a % ai == 0:
		a_list.append(ai)
for bi in range(1, b + 1):
	if b % bi == 0:
		b_list.append(bi)
list_ = [b for b in b_list if b in a_list]
print(list_[-k])


(a, b, k) = map(int, input().split())
ans = [e for e in range(1, min(a, b) + 1) if a % e + b % e == 0]
print(ans[-k])


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


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


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


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


(a, b, k) = (int(i) for i in input().split())
list_ComDiv = []
for i in range(1, min(a, b) + 1):
	if a % i == 0 and b % i == 0:
		list_ComDiv.append(i)
list_ans = sorted(list_ComDiv, reverse=True)
print(list_ans[k - 1])


(integer1, integer2, term) = map(int, input().split())
term_value = max(integer1, integer2)
largest_term = 0
while term_value <= 100:
	if integer1 % term_value == 0 and integer2 % term_value == 0:
		largest_term += 1
	if term == largest_term:
		break
	term_value -= 1
print(term_value)


(a, b, k) = map(int, input().split())
a_divisor = []
ab_divisor = []
for i in range(1, a + 1):
	if a % i == 0:
		a_divisor.append(i)
for j in a_divisor:
	if b % j == 0:
		ab_divisor.append(j)
print(ab_divisor[-k])


(A, B, K) = map(int, input().split())
xi = [n for n in range(100, 0, -1) if A % n == 0 and B % n == 0]
print(xi[K - 1])