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

def get_fact(n):
    arr = []
    a_append = arr.append
    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
            a_append([i, cnt])

    if temp != 1:
        a_append([temp, 1])

    if not arr:
        a_append([n, 1])

    return arr


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




g = gcd(A, B)
fact = [f[0] for f in get_fact(g)]


elem = [1]
e_append = elem.append
for f in fact:
    if f not in elem:
        e_append(f)

print(len(elem))


from itertools import combinations


def get_cf(m, n):
    cf = []
    append = cf.append
    for i in range(1, min(m, n) + 1):
        if m % i == 0 and n % i == 0:
            append(i)
    cf.sort()
    return cf


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



cf = get_cf(A, B)


nC2 = combinations(cf, 2)


cnt = 0
for x, y in nC2:
    if get_cf(x, y) == [1]:
        cnt += 1

print(cnt)

from math import gcd


def get_fact(n):
    arr = []
    a_append = arr.append
    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
            a_append([i, cnt])

    if temp != 1:
        a_append([temp, 1])

    if not arr:
        a_append([n, 1])

    return arr


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




g = gcd(A, B)
fact = [f[0] for f in get_fact(g)]


elem = [1]
e_append = elem.append
for f in fact:
    if f not in elem:
        e_append(f)

print(elem)

print(len(elem))

from itertools import combinations


def get_cf(m, n):
    cf = []
    c_append = cf.append
    for i in range(1, min(m, n) + 1):
        if m % i == 0 and n % i == 0:
            c_append(i)
    cf.sort()
    return cf


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



cf = get_cf(A, B)


nC2 = list(combinations(cf, 2))

print(nC2)


elem = []
e_append = elem.append
for x, y in nC2:
    if get_cf(x, y) == [1]:
        if x not in elem:
            e_append(x)
        if y not in elem:
            e_append(y)

print(len(elem))


def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z



def get_fact(n):
    arr = []
    a_append = arr.append
    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
            a_append([i, cnt])

    if temp != 1:
        a_append([temp, 1])

    if not arr:
        a_append([n, 1])

    return arr


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




g = gcd(A, B)
fact = [f[0] for f in get_fact(g)]


elem = [1]
e_append = elem.append
for f in fact:
    if f not in elem:
        e_append(f)

print(len(elem))

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Accepted