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 = (int(x) for x in input().split())

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

Submission status: Accepted

Solution code:
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

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

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

def main():
    A, B, K = i2nn()
    g = gcd(A, B)
    dd = divisors(g)
    dd.sort()
    dd.reverse()
    n = dd[K-1]
    print(n)

main()

Submission status: Accepted

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

print(ans[-K])

Submission status: Accepted

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

Submission status: Accepted

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

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

print(l_cd[-k])

Submission status: Accepted

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

Submission status: Accepted

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

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

print(L[-K])

Submission status: Accepted

Solution code:
def common_divisor(a, b):
    cd_list = []
    for i in range(1, 101):
        if a % i == 0 and b % i == 0:
            cd_list.append(i)
    return cd_list

A, B, K = map(int, input().split())
print(common_divisor(A, B)[-K])

Submission status: Accepted

Solution code:
from fractions import gcd


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

def d(n):
    div = []
    for i in range(1,n+1):
        if(n % i == 0):
            div.append(i)
    return div
        
a_d = d(a)
b_d = d(b)
s = []
l = []
ab = []

if len(a_d) < len(b_d):
    s = a_d
    l = b_d
else:
    s = b_d
    l = a_d

for i in s:
    if i in l:
        ab.append(i)
print(ab[len(ab)-k])

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0

for i in range(min(a,b), 0, -1):
    if a % i == 0 and b % i == 0:
        cnt += 1

    if cnt == k:
        break

print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(divisor[-k])

Submission status: Accepted

Solution code:
import fractions
a , b , k= map(int, 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:
A,B,K = map(int,input().split())
divisor = []

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

print(divisor[-K])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():

    """ convenient functions
    # for i, a in enumerate(iterable)
    # q, mod = divmod(a, b)
    # divmod(x, y) returns the tuple (x//y, x%y)
    # Higher-order function: reduce(operator.mul, xyz_count, 1)
    # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
    """

    """convenient decorator
    # @functools.lru_cache():
    # to facilitate use of recursive function
        # ex:
        # from functools import lru_cache
        # import sys
        # sys.setrecursionlimit(10**9)
        # @lru_cache(maxsize=None)
        # def fib(n):
        #     if n < 2:
        #         return n
        #     return fib(n-1) + fib(n-2)
        # print(fib(1000))
    """
    
    # import numpy as np
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
    # accumulate() returns iterator! to get list: list(accumulate())
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  # prime factor
        b, e = 2, 0  # base, exponent
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        # TODO: How should I do when n - r is negative?
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
    from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
    import operator
    from operator import itemgetter
    # ex1: List.sort(key=itemgetter(1))
    # ex2: sorted(tuples, key=itemgetter(1,2))
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    # first create factorial_list
    # fac_list = mod_factorial_list(n)
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
    def modinv(a, p = MOD):
        # evaluate reciprocal using Fermat's little theorem:
        # a**(p-1) is identical to 1 (mod p) when a and p is coprime
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        # fac_list = modfactorial_list(100)
        # print(modcomb(100, 5, modfactorial_list(100)))
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    """ initialize variables and set inputs
    # initialize variables
        # to initialize list, use [0] * n
        # to initialize two dimentional array, use [[0] * N for _ in range(N)]
    # set inputs
        # open(0).read() is a convenient method:
        # ex) n, m, *x = map(int, open(0).read().split())
        #     min(x[::2]) - max(x[1::2])
        # ex2) *x, = map(int, open(0).read().split())
        #     don't forget to add comma after *x if only one variable is used
    # preprocessing
        # transpose = [x for x in zip(*data)]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
        # flat = [flatten for inner in data for flatten in inner]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
    # calculate and output
        # output pattern
        # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
    """

    # functions used
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    # single int: int(r())
    # single string: r()
    # single float: float(r())
    # line int: R()
    # line string: r().split()
    # line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
    # lines int: [R() for _ in range(n)]
    """

    if __name__ != '__main__':
        # for test
        sys.stdin = open('sample.txt')

    # ----------------------------------
    # main

    A, B, K = R()
    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)
            exit()
    
    print('too bad!')
    
    # end of main
    # ----------------------------------

    """memo: how to use defaultdict of list
    # initialize
    Dic = defaultdict(list)
    # append / extend
    Dic[x].append(y)
    # for
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math


def divisor(div, N):
    # 約数
    i = 1
    n = N

    while i <= math.sqrt(n):
        if n % i == 0:
            div.add(i)
            div.add(n // i)
        i += 1


A, B, K = map(int, input().split())
a = set()
b = set()
divisor(a, A)
divisor(b, B)

print(sorted(list(a & b), reverse=True)[K - 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [A, B, K] = string_to_int(inputs[0])
    results = []
    small = A if A > B else B
    for i in reversed(range(1, small+1)):
        if A % i == 0 and B % i == 0:
            results.append(i)
    return results[K-1]


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

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

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

print(L[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[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])

Submission status: Accepted

Solution code:
[a,b,k]=map(int,input().split())
a_set=set([])
b_set=set([])
for i in range(1,101):
    if a%i == 0:
        a_set.add(i)
for i in range(1,101):
    if b%i ==0:
        b_set.add(i)
res=a_set&b_set
res=list(res)
res.sort(reverse=True)
print(res[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

    divisors = divisor(A).intersection(divisor(B))
    divisors = sorted(divisors)[::-1]
    print(divisors[K-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
cnt = 0
for i in range(0,101)[::-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())

j = 0

for l in range(min(a,b)):
  i = min(a,b) - l
  if a%i == 0 and b%i == 0:
    j += 1
  if j == k:
    print(i)
    exit()

Submission status: Accepted

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

smaller = min(A, B)
cnt_div = 0
for i in range(1, smaller+1)[::-1]:
  if A%i == 0 and B%i == 0:
    cnt_div += 1
  if cnt_div >= K:
    print(i)
    break

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
A=set()
for i in range(1,a+1):
    if a%i==0:
        A.add(i)
B=set()
for j in range(1,b+1):
    if b%j==0:
        B.add(j)
ans=A & B
ans2=list(ans)
ans3=sorted(ans2, reverse=True)
#print(ans3)
print(ans3[k-1])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
c=min(a,b)
count=0
for i in range(c,0,-1): #a,bの小さいほう～1
    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())
d=[]
for i in range(1,max(a,b)+1):
  if a%i ==0 and b%i ==0:
    d.append(i)
print(d[-k])

Submission status: Accepted

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

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

Submission status: Accepted

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


print(ans_l[-k])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(sorted(S,reverse=True)[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

div_a = make_divisors(a)
div_b = make_divisors(b)

# 内包表記と三項演算子の合わせ技（可読性が最悪なので絶対にやってはいけない）
common_div = [a for a in div_a if a in div_b] if len(div_a) > len(div_b) else [b for b in div_b if b in div_a] 

# print('Aの約数：{}'.format(div_a))
# print('Bの約数：{}'.format(div_b))
# print('A, Bの公約数のリスト：{}'.format(common_div))
print(common_div[::-1][k-1])

Submission status: Accepted

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

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

k = K

for x in range(min(A, B), 0, -1):
    if A % x == 0 and B % x == 0:
        k -= 1
        if k == 0:
            print(x)
            break

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,K = 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)
print(x[-K])

Submission status: Accepted

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

if a > b: n = a
else: n = b
yakusu_list = []
for i in range(1, n+1):
    if a%i == 0 and b%i == 0:
        yakusu_list.append(i)

print(yakusu_list[-k])

Submission status: Accepted

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

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

n = 0

for i in reversed(range(1, GCD(a, b)+1)):
    if a % i == 0 and b % i == 0:
        n += 1

    if n == k:
        print(i)
        break

Submission status: Accepted

Solution code:
def main():
    a,b,k = list(map(int,input().split()))
    divisor = []
    cnt = 0
    for i in range(1,min(a,b) + 1):
        if min(a,b) % i == 0:
            divisor.append(i)
    for i in reversed(divisor):
        if max(a,b) % i == 0:
            cnt += 1
        if cnt == k:
            print(i)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    A,B,K=list(map(int, input().split()))
    divisors=[]
    count = 0
    for i in range(1,min(A,B)+1):
        if min(A,B)%i==0:
            divisors.append(i)
    divisors.reverse()
    for divisor in divisors:
        if max(A,B)%divisor==0:
            count+=1
            if count==K:
                print(divisor)
if __name__ =='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans[-K])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
def gcd(a, b):
    while b:
    	a, b = b, a % b
    return a
GcD = gcd(A,B)
li = []
for i in range(GcD+1):
    if GcD % (i+1) == 0:
        li.append(i+1)
li.sort(reverse=True)
print(li[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

from fractions import gcd

Gcd = gcd(A, B)

c = 0
for i in range(1, Gcd+1):
	if Gcd % i == 0:
		c += 1
	if c == K:
		print(Gcd//i)
		break

Submission status: Accepted

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

list=[]

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

list.sort(reverse=True)

print(list[K-1])

Submission status: Accepted

Solution code:
S = input()
S = S.split()
A = S[0]
B = S[1]
K = S[2]

calcList = list()

a = 1
while a <= int(B):
    if int(A) % a == 0:
        if int(B) % a == 0:
            calcList.append(a)

    a += 1

print(calcList[len(calcList) - int(K)])

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)
l.sort(reverse=True)
print(l[k-1])

Submission status: Accepted

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

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

num_list = sorted(num_list,reverse = True)
print(num_list[K-1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC120 B

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, K = map(int, input().split())
cnt = 0
ans = 0
for i in range(100, 0, -1): # 100 から 1 まで -1ずつ
    if(A % i == 0 and B % i == 0):
        cnt = cnt + 1
    if(cnt == K):
        ans = i
        break #ループ抜ける
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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