Problem p03106 (python)

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

n = min(a,b)

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

Buggy submission (verdict: Runtime Error):
A,B,K = map(int,input().split())

a = A
b = B

def cal_divisor(num):
    prime = [2,3,5,7,11,13]
    ans_list = []
    for i in range(len(prime)):
        ans_list.append([prime[i],0])
    for i in range(len(prime)):
        while True:
            if num % prime[i] == 0:
                num //= prime[i]
                ans_list[i][1] += 1
            if num % prime[i] != 0:
                break
    return ans_list

q = cal_divisor(a)
w = cal_divisor(b)

ans = []
for i in range(len(q)):
    ans.append([q[i][0],min(q[i][1],w[i][1])])
    
ans1 = []
for i in range(len(ans)):
    if ans[i][1] != 0:
        times = ans[i][1]
        for j in range(times+1):
            ans1.append(ans[i][0] ** j)
ans1.append(1)
ans1.sort()

print(ans1[K-1])

Buggy submission (verdict: Runtime Error):
A,B,K = map(int,input().split())

a = A
b = B

def cal_divisor(num):
    prime = [2,3,5,7,11,13]
    ans_list = []
    for i in range(len(prime)):
        ans_list.append([prime[i],0])
    for i in range(len(prime)):
        while True:
            if num % prime[i] == 0:
                num //= prime[i]
                ans_list[i][1] += 1
            if num % prime[i] != 0:
                break
    return ans_list

q = cal_divisor(a)
w = cal_divisor(b)

ans = []
for i in range(len(q)):
    ans.append([q[i][0],min(q[i][1],w[i][1])])
    
ans1 = []
for i in range(len(ans)):
    if ans[i][1] != 0:
        times = ans[i][1]
        for j in range(times+1):
            ans1.append(ans[i][0] ** j)

ans1.sort()

if K != 1:
    print(ans1[K-1])
if K == 1:
    print(1)

Buggy submission (verdict: Runtime Error):
A,B,K = map(int,input().split())

a = A
b = B
if a == b == 1:
    print('1')
    exit()
def cal_divisor(num):
    prime = [2,3,5,7,11,13]
    ans_list = []
    for i in range(len(prime)):
        ans_list.append([prime[i],0])
    for i in range(len(prime)):
        while True:
            if num % prime[i] == 0:
                num //= prime[i]
                ans_list[i][1] += 1
            if num % prime[i] != 0:
                break
    return ans_list

q = cal_divisor(a)
w = cal_divisor(b)

ans = []
for i in range(len(q)):
    ans.append([q[i][0],min(q[i][1],w[i][1])])


ans1 = []
for i in range(len(ans)):
    if ans[i][1] != 0:
        times = ans[i][1]
        for j in range(times+1):
            ans1.append(ans[i][0] ** j)
ans1.sort() 
print(ans1[K-1])

Buggy submission (verdict: Runtime Error):
A,B,K = map(int,input().split())

a = A
b = B
if a = b= 1:
    print('1')
    exit()
def cal_divisor(num):
    prime = [2,3,5,7,11,13]
    ans_list = []
    for i in range(len(prime)):
        ans_list.append([prime[i],0])
    for i in range(len(prime)):
        while True:
            if num % prime[i] == 0:
                num //= prime[i]
                ans_list[i][1] += 1
            if num % prime[i] != 0:
                break
    return ans_list

q = cal_divisor(a)
w = cal_divisor(b)

ans = []
for i in range(len(q)):
    ans.append([q[i][0],min(q[i][1],w[i][1])])


ans1 = []
for i in range(len(ans)):
    if ans[i][1] != 0:
        times = ans[i][1]
        for j in range(times+1):
            ans1.append(ans[i][0] ** j)
ans1.sort() 
print(ans1[K-1])