Problem: Given are positive integers A and B.  Let us choose some number of positive common divisors of A and B.  Here, any two of the chosen divisors must be coprime.  At most, how many divisors can we choose?  Definition of common divisor  An integer d is said to be a common divisor of integers x and y when d divides both x and y.  Definition of being coprime  Integers x and y are said to be coprime when x and y have no positive common divisors other than 1.  Definition of dividing  An integer x is said to divide another integer y when there exists an integer \alpha such that y = \alpha x.

Submission attempts (in order):
import math, fractions

a, b = map(int, input().split())
n = int(fractions.gcd(a, b))
res = 0
for i in range(3, n):
    if a % i or b % i:
        continue
    dest = int(math.sqrt(i))
    for j in range(2, dest+1):
        if i % j == 0:
            break
    else:
        res += 1
if n >= 2:
    print(res + 2)
else:
    print(res + 1)

a, b = map(int, input().split())
n = min(a, b) // 2
t = list(range(2, n+1))
for i in range(len(t)):
    if t[i] == -1:
        continue
    if a % t[i] == 0 and b % t[i] == 0:
        for j in range(i+1, len(t)):
            if t[j] == -1:
                continue
            if t[j] % t[i] == 0:
                print(t[j], t[i])
                t[j] = -1
    else:
        t[i] = -1

print(sum([1 for v in t if v != -1]) + 1)

print(1)

a, b = map(int, input().split())
n = min(a, b) // 2
t = list(range(2, n+1))

#    if t[i] == -1:
#        continue
#    if a % t[i] == 0 and b % t[i] == 0:
#        for j in range(i+1, len(t)):
#            if t[j] == -1:
#                continue
#            if t[j] % t[i] == 0:
#                print(t[j], t[i])
#                t[j] = -1
#    else:
#        t[i] = -1
print(1)

a, b = map(int, input().split())
n = min(a, b) // 2
#t = list(range(2, n+1))

#    if t[i] == -1:
#        continue
#    if a % t[i] == 0 and b % t[i] == 0:
#        for j in range(i+1, len(t)):
#            if t[j] == -1:
#                continue
#            if t[j] % t[i] == 0:
#                print(t[j], t[i])
#                t[j] = -1
#    else:
#        t[i] = -1
print(1)

a, b = map(int, input().split())
n = min(a, b) // 2
*t, = [True] * (n + 1)

#    if not t[i]:
#        continue
#    if a % t[i] == 0 and b % t[i] == 0:
#        for j in range(i+1, len(t)):
#            if t[j] == -1:
#                continue
#            if t[j] % t[i] == 0:
#                print(t[j], t[i])
#                t[j] = -1
#    else:
#        t[i] = -1
print(1)

import fractions
a, b = map(int, input().split())
n = fractions.gcd(a, b)
*t, = range(2, n+1)

#    if t[i] == -1:
#        continue
#    if a % t[i] == 0 and b % t[i] == 0:
#        for j in range(i+1, len(t)):
#            if t[j] == -1:
#                continue
#            if t[j] % t[i] == 0:
#                print(t[j], t[i])
#                t[j] = -1
#    else:
#        t[i] = -1
print(1)

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

def getPrimeFactors(x):
    ans = []
    for d in range(2, int(x**0.5)+1):
        while x%d == 0:
            ans.append(d)
            x //= d
    if x != 1:
        ans.append(x)
    return ans

res_a = getPrimeFactors(a)
res_b = getPrimeFactors(b)

res = len(set(res_a) & set(res_b))
print(res + 1)

Verdicts: Time Limit Exceeded

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted