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

Submission status: Accepted

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

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())
for i in range(101,0,-1):
    if a%i==0 and b%i==0:
        k-=1
        if k==0:
            print(i)
            exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))
A, B, K = inpl()
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:
import sys

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


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

l = []
for i in range(1,101)[::-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())
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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def bit_count(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

A,B,K = inputIL()

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

Submission status: Accepted

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

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたらFalse
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  # [1, 0, 3]

'''

def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''


########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

def main():

    steps=0
    state=0
    w=1
    j=0
    k=0
    ans=[]
    #n=int(input())
    a,b,k=map(int, input().split(" "))
    #nl=list(map(int, input().split(" ")))#数字の時
    #s=input()
    #a=[int(i) for i in s]#int取るとstrでも行ける
    #print(a)
    i=1
    step=0
    while step<min(a,b):
     #print(a, b, i  )
     if a%i==0 and b%i==0:
         step +=1
         ans.append(i)
     if i>min(a,b):
    #    print("stop")
        break
     i +=1

    print(ans[-k])
    for i in range(1,n+1,):#これで1個飛ばしループになる
     #print(i)
     pass


    #if state in known_states and not flag: # state => 2 steps => 5
        #こうやってある要素がリストの中にあるか探すのか
    #print(f'steps: {steps}, state: {state}')
    #こう書いてあるとデバックしやすい

    #dp= [[0]*3 for i in range(5)]#列　行
    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    "1行1つの整数を入力を取得し、整数と取得する"
    #nl=list(map(int, input().split(" ")))#数字の時
    #print(number_list)
    "12 21 332 とか入力する時に使う"
    "1行に複数の整数の入力を取得し、整数として扱う"
    #brray=[list(map(int, input().split(" ")))for i in range(N)
    #print(brray)



    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]#内包表記に慣れろ
    #print(pin_l)

    ls = ["a", "b", "c", "d", "e"]


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

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:
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()


def main():
    A, B, K = map(int, input().split())
    d = gcd(A, B)
    div = []
    div2 = []
    root = int(d ** 0.5)
    if root ** 2 == d:
        for i in range(1, root):
            if d % i == 0:
                div.append(i)
                div2.append(d // i)
        div.append(root)
    else:
        for i in range(1, root + 1):
            if d % i == 0:
                div.append(i)
                div2.append(d // i)
    div2.reverse()
    div = div + div2
    for _ in range(K - 1): div.pop()
    print(div[-1])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

a, b, k = Is()
g = gcd(a, b)
count = 0
for i in reversed(range(1, g+1)):
    if g % i == 0:
        count += 1
        if count == k:
            print(i)
            exit()

Submission status: Accepted

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

C = max(A, B)
l = []
for n in range(1, C+1):
    if A % n == 0 and B % n == 0:
        l.append(n)
l.sort(reverse=True)

for i in range(len(l)):
    if i + 1 == K:
        print(l[i])

Submission status: Accepted

Solution code:
A,B,K=map(int,input().split())
c=[]
for i in range(1,min(A,B)+1):
  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())
x=min(A,B)
count=0
while x>0:
    if A%x==0 and B%x==0:
        count+=1
        if count==K:
            ans=x
            break
    x-=1
print(ans)

Submission status: Accepted

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

ans = []
for x in range(1,max(a, b)+1):
    if(a % x == 0 and b % x == 0):
        ans.append(x)
print(ans[len(ans)-k])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
a, b, k = map(int, input().split())
g = gcd(a, b)
cnt = 0
for i in reversed(range(1, g+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())
x = min(a, b)
c = 0
while x > 0:
    if a % x == 0 and b % x == 0:
        c += 1
    if c == k:
        print(x)
        exit()
    x -= 1

Submission status: Accepted

Solution code:
import sys
import math
import bisect

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

X = []
for x in range(1,min([A,B])+1):
  if A%x==0 and B%x==0:
    X.append(x)
print(X[-1*K])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def gcd(a: int, b: int):
    if a < b:
        return gcd(b, a)
    while b != 0:
        a, b = b, a % b
    return a


def solve(A: int, B: int, K: int):
    g = gcd(A, B)
    c = [i for i in range(1, g + 1) if g % i == 0]
    print(c[-K])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, K)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

count=[]
if a<=b:
  for i in range(a,0,-1):
    if a%i==0 and b%i==0:
      count.append(i)
if a>b:
  for j in range(b,0,-1):
    if a%j==0 and b%j==0:
      count.append(j)
print(count[k-1])

Submission status: Accepted

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

cnt = 0
for num in reversed(range(1, min(A, B)+1)):
    if A%num==0 and B%num==0:
        cnt += 1

    if cnt == K:
        print(num)
        break

Submission status: Accepted

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

print(lst[k-1])

Submission status: Accepted

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


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


def factors(a):
    f = []
    for n in range(a, 0, -1):
        if a % n == 0:
            f.append(n)
    return f


ans = factors(gcd(A, B))[K - 1]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,K=map(int,input().split())
l=[]
p=A
q=B
if A>B:
    A=q
    B=p
for i in range(1,B+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 = list(map(int,input().split()))
L = [i for i in range(100,0,-1) if A%i == 0 and B%i == 0]
print(L[K-1])

Submission status: Accepted

Solution code:
#K番目に"大きいもの"なのでおおきいものから調べないといけない

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

ans = 1
counter = 0

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

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools

a, b, k = 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)

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

Submission status: Accepted

Solution code:
a, b, c = 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 == c:
            print(i)
            break

Submission status: Accepted

Solution code:
#import math
from fractions import gcd
'''
3.7 以降は、Math
以前は、
from fractions import gcd 
'''
a, b, k = map(int, input().split())
# 最大公約数のK倍。

'''
def lcm(x, y):
    # // for integer answer
    #ll = (x * y) // math.gcd(x, y)
    ll = (x * y) // gcd(x, y)
    return ll
'''

ans = [i for i in range(1, 200) if (a % i == 0 and b % i == 0)]
print(ans[-k])
# print(int(ans))

Submission status: Accepted

Solution code:
A, B, K = 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)
            break

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

#a,b,k=8,12,2

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

print(ans)

Submission status: Accepted

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

cnt=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
ct=a
ct2=0
while 1:
    if (a%ct==0)and(b%ct==0):
        ct2+=1
    if ct2==c:
        break
    ct-=1
print(ct)

Submission status: Accepted

Solution code:
a,b,k = map(int, input().split())
 
for i in range(min(a,b),0,-1):
  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())
wari=[]
for i in range(1,101):
    if a%i==0 and b%i==0:
        wari.append(i)

print(wari[-k])

Submission status: Accepted

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

cnt = 0
for i in range(1,101)[::-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())
i=min(a,b)
count=0
while True:
    if a%i==0 and b%i==0:
        count+=1
        if count==k:
            print(i)
            break
    i-=1

Submission status: Accepted

Solution code:
def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

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

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

x = gcd(A, B)
X = divisor(x)

print(X[K - 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 == B%i == 0:
        cnt += 1
        if cnt == K:
            print(i)
            break

Submission status: Accepted

Solution code:
a,b,k = 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)
    exit()

Submission status: Accepted

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

Submission status: Accepted

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

count = []

s = A if A < B else B

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

Submission status: Accepted

Solution code:
a,b,k = 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)
print(li[-k])

Submission status: Accepted

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

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

divisible.sort(reverse=True)
print(divisible[k - 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:
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

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

cd = []

if A > B:
  nums = [i for i in range(1, B+1)]
elif A < B:
  nums = [i for i in range(1, A+1)]
else:
  nums = [i for i in range(1, A+1)]

for i in nums:
  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())

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

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

Submission status: Accepted

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

i=1
cnt=0
result=[]

while i<=min(a,b):
  if a%i==0 and b%i==0:
    cnt+=1
    result.append(i)
  i+=1

print(result[-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 = ls[::-1]
print(ls[k-1])

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

for i in range(max(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:
A,B,K = map(int,input().split())
a = []
for n in range(1,max(A,B)+1):
    if A%n==0 and B%n==0:
        a.append(n)
print(a[::-1][K-1])

Submission status: Accepted

Solution code:
def main():
    a, b, k = map(int, input().split())
    from fractions import gcd
    g = gcd(a, b)

    def yakusuu(a):
        yakusuu = set()
        for i in range(1, int(a**0.5)+1):
            if a % i == 0:
                yakusuu.add(i)
                yakusuu.add(a//i)
        yakusuu = sorted(list(yakusuu))
        return yakusuu

    print(yakusuu(g)[::-1][k-1])


main()

Submission status: Accepted

Solution code:
A,B,K = map(int,input().split())
L = 0
ans = 0
for i in reversed(range(1,2000)):
  if A%i == 0:
    if B%i == 0:
      L += 1
    else:
      L += 0
  else:
    L += 0
  if L == K:
    ans = i
    break
print(ans)

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:
      print(i)
      break

Submission status: Accepted

Solution code:
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(a,b,k):
    res = []
    for i in range(1,min(a,b)+1):
        if a % i == 0 and b % i == 0:
            res.append(i)
    return res[-k]        
            
a,b,k = mi()
print(main(a,b,k))

Submission status: Accepted

Solution code:
def main():
    A, B, K = map(int, input().split())
    results = calc(A, B)
    print(results[K - 1])

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

  for i in range(min(A, B), 0, -1):
    if(A % i == 0 and B % i == 0):
      o += 1

      if(K == o):
        print(i)
        break
    

if __name__ == "__main__":
  main()

Submission status: Accepted

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

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

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

l = cf(a,b)

l.sort(reverse=True)

print(l[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list1 = [int(i) for i in input().split()]
lista=[]
for i in range(1,int(list1[0])+1):
  if (int(list1[0])% int(i)==0) and  (int(list1[1])% int(i)==0): 
    lista.append(i)
c=int(list1[2])
lista.reverse()
#print(lista)
print(lista[c-1])

Submission status: Accepted

Solution code:
def find_pledge(i, j):
    mylist = []
    for m in range(1, 101):
        if i % m == 0 and j % m == 0:
            mylist.append(m)
    return mylist

a, b, k = map(int, input().split())
mylist = find_pledge(a, b)
print("{}".format(mylist[len(mylist)-k]))

Submission status: Accepted

Solution code:
a, b, k = list(map(int, input().split()))
la = []
lb = []
for i in range(1, a+1):
    if a % i == 0:
        la.append(i)
        lsas = sorted(set(la), key=la.index)
        for j in lsas:
            if b % j == 0:
                lb.append(j)

lsbs = sorted(set(lb), key=lb.index)
print(lsbs[len(lsbs)-k])