Problem: 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.

Submission attempts (in order):
a, b, k = map(int, input().split())

ans = 0

if (a < b):
    li = [i for i in range(b+1) if (a % i == 0 && b % i == 0 && i != 0)]
    ans = li[k-1]
else:
    li = [i for i in range(a+1) if (a % i == 0 && b % i == 0 && i != 0)]
    ans = li[k-1]

print(ans)

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

ans = 0

if (a < b):
    list = [i for i in range(b+1) if (a % i == 0 && b % i == 0 && i != 0)]
    ans = list[k-1]
else:
    list = [i for i in range(a+1) if (a % i == 0 && b % i == 0 && i != 0)]
    ans = list[k-1]

print(ans)

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

ans = 0

lista = range(a+1)
aa = lista.pop(0)

listb = range(b+1)
bb = listb.pop(0)

if (a < b):
    li = [i for i in listb if (a % i == 0 && b % i == 0)]
    li = sorted(li, reverse=True)
    ans = li[k-1]
else:
    li = [i for i in lista if (a % i == 0 && b % i == 0)]
    li = sorted(li, reverse=True)
    ans = li[k-1]

print(ans)

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

ans = 0

lista = range(a+1)
aa = lista.pop(0)

listb = range(b+1)
bb = listb.pop(0)

if (a < b):
    li = [i for i in listb if a % i == 0 && b % i == 0]
    li = sorted(li, reverse=True)
    ans = li[k-1]
else:
    li = [i for i in lista if a % i == 0 && b % i == 0]
    li = sorted(li, reverse=True)
    ans = li[k-1]

print(ans)

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

ans = 0

lista = range(a+1)
aa = lista.pop(0)

listb = range(b+1)
bb = listb.pop(0)

if (a < b):
    li = [i for i in listb if (a % i == 0 && b % i == 0)]
    ans = li[k-1]
else:
    li = [i for i in lista if (a % i == 0 && b % i == 0)]
    ans = li[k-1]

print(ans)

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

ans = 0

lista = range(a+1)
aa = lista.pop(0)

listb = range(b+1)
bb = listb.pop(0)

if (a < b):
    li = [i for i in lista if a % i == 0 && b % i == 0]
    li = sorted(li, reverse=True)
    ans = li[k-1]
else:
    li = [i for i in listb if a % i == 0 && b % i == 0]
    li = sorted(li, reverse=True)
    ans = li[k-1]

print(ans)

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

ans = 0

if (a < b):
    list = [i for i in range(b) if a % i == 0 && b % i == 0 && i != 0]
    ans = list[k-1]
else:
    list = [i for i in range(a) if a % i == 0 && b % i == 0 && i != 0]
    ans = list[k-1]

print(ans)

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

ans = 0

lista = list(range(a+1))
aa = lista.pop(0)

listb = list(range(b+1))
bb = listb.pop(0)

if (a < b):
    li = [i for i in lista if a % i == 0 && b % i == 0]
    li = sorted(li, reverse=True)
    ans = li[k-1]
else:
    li = [i for i in listb if a % i == 0 && b % i == 0]
    li = sorted(li, reverse=True)
    ans = li[k-1]

print(ans)

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

ans = 0

if (a < b):
    list = [i for i in range(b) if a % i == 0 && b % i == 0]
    ans = list[k-1]
else:
    list = [i for i in range(a) if a % i == 0 && b % i == 0]
    ans = list[k-1]

print(ans)

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

ans = 0

lista = list(range(a+1))
aa = lista.pop(0)

listb = list(range(b+1))
bb = listb.pop(0)

if (a < b):
    li = [i for i in lista if a % i == 0 and b % i == 0]
    li = sorted(li, reverse=True)
    ans = li[k-1]
else:
    li = [i for i in listb if a % i == 0 and b % i == 0]
    li = sorted(li, reverse=True)
    ans = li[k-1]

print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted