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: Runtime Error

Solution code:
for i in range(1, a):
    if a % i == 0:
        li.append(i)
    else:
        continue

for i in range(1, b):
    if b % i == 0:
        li.append(i)
    else:
        continue

li2 =[]
for n in range(len(li)):
    if li.count(li[n]) == 2:
        li[n] = num
        li2.append(num)
        li.remove(num)
        li.remove(num)
    else:
        continue

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

Submission status: Runtime Error

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

S = [1]

for i in range(2,min(A,B)):
    if A % i == 0 and B % i == 0:
        S.append(i)

S.reverse()

print(S[K-1])

Submission status: Runtime Error

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

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

if warikiru == []:
    print(1)
else:
    print(warikiru[-1::-1][K-1])

Submission status: Runtime Error

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

import math
import sys

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

gcd_num = math.gcd(A, B)

if K==1:
    print(gcd_num)
    sys.exit()

yakusuu_array = []
for i in range(1,gcd_num):
    if gcd_num % i == 0:
        yakusuu_array.append(i)
        yakusuu_array.sort(reverse=True)

print(yakusuu_array[K-2])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

S = [1]

for i in range(2,min(A,B)):
    if A % i == 0 and B % i == 0:
        S.append(i)

S.append()

print(S[K-1])

Submission status: Runtime Error

Solution code:
a, b, k = map(int, input().strip().split(' '))
i = 1
l = []
while len(l)<k:
    if a%i=0 and b%i=0 or i%2=0:
        l.append(i)
    else:
        pass
    i=i+1
print(l[-1])

Submission status: Runtime Error

Solution code:
import math
li = list(map(int,input().split()))
a=li[0]
b=li[1]
k=li[2]
saidai=math.gcd(a,b)
yakusuu=[]
for i in range(100):
    if saidai%(i+1)==0:
        yakusuu.append(i+1)
yakusuu.sort()
yakusuu.reverse()
print(yakusuu[k-1])

Submission status: Runtime Error

Solution code:
x,y,z = map(int,input().split())
n = (y if x < y else x) 
array = []
for i in range(1,n):
	if (x%i==0 and y%i==0):
		array.append(i)
print(array[z-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
a, b, k = [int(i) for i in input().split() ]
x=math.gcd(a,b)
i = 1
for j in range(2, 101):
    if i == k:
        break
    if x % j == 0:
        x = int(x/j)
        i += 1
print(x)

Submission status: Runtime Error

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

aa =[]
bb=[]
cc=[]

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

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

if a==1:
    aa.append(1)

if b==1:
    bb.append(1)

cc=sorted(list(set(aa) & set(bb)),reverse=True)
print(cc[k-1])

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[2]:


import sys


# In[18]:


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


# In[19]:


def yakusuu(x):
    yakusuu_array = []

    for i in range(1, x):
        if num % i == 0:
            yakusuu_array.append(i)
    
    return yakusuu_array


# In[21]:


if K > 1:
    print(list(set(yakusuu(A)) & set(yakusuu(B)))[K-1])
else:
    print(1)

Submission status: Runtime Error

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

S = [1]

for i in range(2,min(A,B)):
    if A % i == 0 and B % i == 0:
        S.append(i)

print(S[K-1])

Submission status: Runtime Error

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

gcd = math.gcd(a, b)
list_gcd = list()

for i in range(1, int(gcd/2) + 1):
    if gcd % i == 0:
        list_gcd.append(i)

list_gcd.append(gcd)
print(list_gcd[-k])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

gcd = math.gcd(a, b)
list_gcd = list()

for i in range(1, int(gcd/2) + 1):
    if gcd % i == 0:
        list_gcd.append(i)

list_gcd.append(gcd)
print(list_gcd[-k])

Submission status: Runtime Error

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

import math

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

gcd_num = math.gcd(A, B)

if K==1:
    print(gcd_num)
    exit()

yakusuu_array = []
for i in range(1,gcd_num):
    if gcd_num % i == 0:
        yakusuu_array.append(i)
        yakusuu_array.sort(reverse=True)

print(yakusuu_array[K-2])

Submission status: Runtime Error

Solution code:
a, b, k = [int(x) for x in input().split()]
al = set()
for i in range(1, a):
    if a%i == 0:
        al.add(i)
bl = set()
for i in range(1, b):
    if b%i == 0:
        bl.add(i)
kk = list(al | bl)
print(kk[k-1])

Submission status: Runtime Error

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

S = [1]

for i in range(2,min(A,B)):
    if A % i == 0 or B % i == 0:
        S.append(i)

print(S[K-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

aa =[]
bb=[]
cc=[]

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

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

if a==1:
    aa.append(1)

if b==1:
    bb.append(1)

cc=sorted(list(set(aa) & set(bb)))
print(cc[k-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

ans = []

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

Submission status: Runtime Error

Solution code:
a,b,k=map(int,input().split())
c=0
n=0
if a>b:
    n=a-b
if b>a:
    n=b-a
if a==b:
    n=1
while(True):
    if(a%n==0)&(b%n==0):
        c=c+1
    if c==k:
        break
    n=n-1
print(n)

Submission status: Runtime Error

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):
    if (A%i==0) & (B%i==0):
        ans.append(i)
print(ans[len(ans)-K])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

A = []
B = []
for i in range(1,a):
    if a % i == 0:
        A.append(i)
for i in range(1,b):
    if b % i == 0:
        B.append(i)
common = list(set(A) & set(B))
common.sort()
print(common[k-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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)
(atcoder) @lx

Submission status: Runtime Error

Solution code:
in_str = input()
input_list = list(map(int,in_str.split()))
A = input_list[0]
B = input_list[1]
K = input_list[2]
count = 0
ans = 0
for i in range(100):
  if(A/i==0 and B/i==0):
    ans = i
    count+=1
    if(count==K):
      break
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = []

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

print(ans[-k])

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

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

num = []
mini = min(a, b)
for i in range(1, mini):
    if mini % i == 0:
        num.append(i)
num.sort()
print(num[k-1])

Submission status: Runtime Error

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

if int(A)==1 or int(B)==1:
    print(1)
else:
    div = [x for x in range(1, min(int(A),int(B))) if int(A)%x==0 and int(B)%x==0]
    print(div[-int(K)])

Submission status: Runtime Error

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

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

print(sei)

Submission status: Runtime Error

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

S = []

for i in range(1, min(A,B)):
    if (A % i == 0) or (B % i == 0):
        S.append(i)
        

if A == 1 and B == 1 and K == 1:
    print(1)
else:
    print(S[K-1])

Submission status: Runtime Error

Solution code:
import sys
from sys import stdin

def f(num):
  d = []
  if num != 1:
    for i in range(1,num):
      if num % i == 0:
    	  d.append(i)
  else:
      d = [1]
  return d

A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
a = f(A)
b = f(B)
d = set(a)&set(b)
d = list(d)
print(d[C-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = []

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
a,b,k=map(int,input().split())
import math
max_gcd=math.gcd(a, b)
yakusuu_array=[]
if k==1:
    print(max_gcd)
else:
    for i in range(1,max_gcd):
        if max_gcd % i == 0:
            yakusuu_array.append(i)

    print(yakusuu_array[-(k-1)])

Submission status: Runtime Error

Solution code:
a,b,k = map(int, input().split())
import math
import sys
c = math.gcd(a, b)
ls = []
for i in range(1, c):
    if c % i == 0:
        ls.append(i)

print(ls[k-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from fractions import gcd
a,b,k = map(int,input().split())
mods = []
for i in range(1,min(a,b)):
    if a % i == 0 and b % i == 0:
        mods.append(i)
mods.sort(reverse=True)
if len(mods) == 1:
    print(mods[0])
else:
    print(mods[k-1])

Submission status: Runtime Error

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:
        count += 1
        t_list.append(i)
        
        

        
print(t_list[-K])

Submission status: Runtime Error

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

q = [1]

for i in range(2,50):
  if a % i == 0 and b % i == 0:
    q.append(i)

print(q[k - 1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
A, B, K = [int(i) for i in input().split()]
cnt = 1
while True:
    if A % min(A,B) == B % min(A, B) == 0:
        break
    if A > B:
        A %= B
    else:
        B %= A

target = min(A,B)
print(target)
for i in range(2,target):
    if target % i == 0:
        cnt += 1
    if cnt == K:
        break
print(int(target / i))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

nums = []

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

if nums == []:
    print(1)
else:
    print(nums[K-1])

Submission status: Runtime Error

Solution code:
import sympy

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


C = sympy.gcd(A,B)

y = []
for i in range(C):
    if C % (i+1) == 0:
        y.append(i+1)


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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

aa =[]
bb=[]
cc=[]

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

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




cc=list(set(aa) & set(bb))
if cc==[]:
    print(1)
    exit()
print(cc[k-1])

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
import pandas as pd
import torch

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

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

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

Submission status: Runtime Error

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

if(a < b):
  tmp = a
  a = b
  b = tmp
  
for i in range(a):
  if(i != 0):
   if((a%i == 0)and(b%i == 0)):
    gcd.append(i)
 
print(gcd[-k])

Submission status: Runtime Error

Solution code:
import math

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

d = math.gcd(A, B)

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

ass = list(set(divisor(d)))
#print(ass)
out = ass[-K]
print(out)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A, B, K = [int(i) for i in input().split()]
cnt = 1
while True:
    if A % min(A,B) == B % min(A, B) == 0:
        break
    if A > B:
        A %= B
    else:
        B %= A

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

Submission status: Runtime Error

Solution code:
import math

a,b,k = map(int,input().split())
x = math.gcd(a,b)
list_num = []
for i in range(1,x+1):
    if x % i == 0:
        list_num.append(i)
list_num = sorted(list_num,reverse=True)
print(list_num[k-1])

Submission status: Runtime Error

Solution code:
from math import gcd
A, B, K = map(int, input().split())
d = gcd(A, B)
print([i for i in range(100, 0, -1) if d % i == 0][K-1])

Submission status: Runtime Error

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

ans = []
for i in range(1, a if a < b else b):
    if a%i == 0 and b%i == 0:
        ans.append(i)

print(ans[k-1])

Submission status: Runtime Error

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

g=math.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: Runtime Error

Solution code:
import math

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


C = math.gcd(A,B)

y = []
for i in range(C):
    if C % (i+1) == 0:
        y.append(i+1)


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

Submission status: Runtime Error

Solution code:
A,B,K = [int(_) for _ in input().split]
M = A*B
print(M * K)

Submission status: Runtime Error

Solution code:
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
a,b,k=IL()
c=[]
for i in range(1,max(a,b)):
    if a%i==0 and b%i==0:
        c.append(i)
print(c[-k])

Submission status: Runtime Error

Solution code:
from fractions import gcd
a,b,k = map(int,input().split())
mods = []
for i in range(1,max(a,b)):
    if a % i == 0 and b % i == 0:
        mods.append(i)
print(mods[k-1])

Submission status: Runtime Error

Solution code:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;


int main(){
   int A,B;
   long long K;
   cin >> A >> B>>K;
   for(int i=min(A,B);i>=1; i--){
      if(A%i==0 && B%i==0){
         K--;
         if(K==0){
            cout << i << endl;
            return 0;
         }
      }
   }
   return 0;
}

Submission status: Runtime Error

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

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