Problem:
 Score : 400 points    Problem Statement 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 .       Constraints  All values in input are integers.  1 \leq A, B \leq 10^{12}         Input Input is given from Standard Input in the following format:  A  B       Output Print the maximum number of divisors that can be chosen to satisfy the condition.        Sample Input 1 12 18      Sample Output 1 3  12 and 18 have the following positive common divisors: 1 , 2 , 3 , and 6 .  1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1 , 2 , and 3 , which achieve the maximum result.       Sample Input 2 420 660      Sample Output 2 4       Sample Input 3 1 2019      Sample Output 3 1  1 and 2019 have no positive common divisors other than 1 .

Solution (Python):
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def coprime(a, b) : 
    return (gcd(a, b) == 1) 

def make_div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return sorted(divisors)

def count(arr):
    ans = set()
    for i in arr:
        if i == 1:
            ans.add(i)
            continue
        else:
            flag = 1
            for j in ans:
                if j != 1:
                    if (i % j) == 0:
                        flag = 0
                        break
            if flag == 1:
                ans.add(i)
    return(len(ans))

A,B = list(map(int,input().split()))
gcd_ab = gcd(A,B)
arr = make_div(gcd_ab)
n = len(arr)
print(count(arr))

Solution (Python):
def f(n):
    result = set()
    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
            result.add(i)

    if temp != 1:
        result.add(temp)

    return result


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

fa = f(a)
fb = f(b)

print(len(fa & fb)+1)

Solution (Python):
import fractions

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

N = fractions.gcd(A, B)

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

  
if((A-1)*(B-1) == 0):
  print(1)
else:
  print(1 + len(factorization(N)))

Solution (Python):
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

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

def count_(upper_num):
    data = [2] + list(range(3,upper_num+1,2))
    idx = 0
    length = len(data)
    while idx < length:
        prime = data[idx]
        data = [d for d in data if (d==prime or d % prime != 0)]
        idx += 1
        length = len(data)
    
    return data

def make_divisors(n):
    divisors = [1]
    i = 2 
    max_int = int(n**0.5)+1
    while n >1:

        if i >= max_int:

            divisors.append(n)
            break
        
        
        if n % i == 0:
            divisors.append(i)
            max_int = int((n//i)**0.5)+1
            while n%i == 0:
                n = n//i
                
        i += 1

    divisors = list(set(divisors))

    return divisors

print(len(make_divisors(gcd(A,B))))

Solution (Python):
import math

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

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

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

divisors_a = set(make_divisors(a))
divisors_b = set(make_divisors(b))

common_divisors = []
for a in divisors_a:
    if a in divisors_b:
        common_divisors.append(a)

counter = 0
for i in common_divisors:
    if is_prime(i) or i == 1:
        counter += 1
print(counter)

Solution (Python):
import math as m
import fractions as fr

def is_prime(n): 
    if n == 1: return False
    for k in range(2, int(m.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table   

a, b = map(int, input().split())
g = fr.gcd(a,b)
tb = divisor(g)

count = 1
for i in tb:
    if is_prime(i):
        count += 1

print(count)

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

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

agcd = gcd(a,b)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

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

    for k in range(2, int(n**0.5) + 1):
        if n % k == 0:
            return False

    return True

x = make_divisors(agcd)
ans = 1
for _x in x:
    ans += is_prime(_x)

print(ans)

Solution (Python):
def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(y,x%y)
def factorize(n):
    f=[]
    p=2
    while p**2<=n:
        while n%p==0:
            n=n//p
            f.append(p)
        p+=1
    if n!=1:
        f.append(n)
    return f

def main():
    a,b=map(int,input().split())
    g=gcd(a,b)
    F=factorize(g)
    print(len(set(F))+1)
    
if __name__=='__main__':
    main()

Solution (Python):
import sys

def factorization(n):
    d = dict()
    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
            d[i] = cnt
    
    if temp != 1:
        d[temp] = 1
    
    if len(d) == 0:
        d[n] = 1
    
    return d

def main():
    input = sys.stdin.readline
    A, B = map(int, input().split())
    if A == B == 1:
        return 1

    Af = factorization(A,)
    Bf = factorization(B,)
    cnt = 1
    for a in Af.keys():
        if a in Bf.keys():
            cnt += 1

    return cnt

if __name__ == '__main__':
    print(main())

Solution (Python):
import fractions
a, b = map(int, input().split())
n = fractions.gcd(a, b)
i = 1
ass = [1]
for i in range(2, int(n**0.5)+1):
    while n % i == 0:
        ass.append(i)
        n = n//i
if n != 1:
    ass.append(n)
print(len(set(ass)))

Solution (Python):
import fractions

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



gcd = fractions.gcd(A, B)


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



f = factorization(gcd)

if f == [[1, 1]]:
    print(1)
else:
    
    ans = len(f) + 1
    print(ans)

Solution (Python):
import math

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

maxp = int(math.sqrt(min(a,b))) + 1

primes = [1]
is_prime = [True] * (maxp + 1)

i = 2
cnt = 1
for i in range(2, maxp+1):
    
    if is_prime[i]:
        primes.append(i)
        if a % i == 0 and b % i == 0:
            
            cnt += 1
        while a % i == 0:
            a = a // i
        while b % i == 0:
            b = b // i
    j = i * i
    while j <= maxp:
        is_prime[j] = False
        j += i


if a > 1 and b > 1:
    if max(a, b) % min(a, b) == 0:
        cnt += 1

print(cnt)

Solution (Python):
import fractions

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


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors


c = make_divisors(a)
d = make_divisors(b)
e = []
for i in c:
    if i in d:
        e.append(i)

e.pop(0)
e.sort()

gcd_list = [1]
for i in e:
    count = 0
    for j in gcd_list:
        if fractions.gcd(i, j) != 1:
            break
        else:
            count += 1
        if count == len(gcd_list):
            gcd_list.append(i)

print(len(gcd_list))

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

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

def coprime(a, b):
    return gcd(a, b) == 1

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

G = gcd(A, B)
l = make_divisors(G)
l.remove(1)
if len(l) == 0:
    print(1)
else:
    c = 1
    for i in range(len(l)):
        for j in range(i):
            if not coprime(l[i], l[j]):
                break
        else:
            c += 1
    print(c)

Solution (Python):

import fractions

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

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

if fractions.gcd(A,B) == 1:
    print(1)
else:
    print(len(factorization(fractions.gcd(A,B)))+1)

Solution (Python):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

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

g = divisor(gcd(A,B))


cnt = 0
for i in g:
    if len(divisor(i)) <= 2:
        cnt += 1

print(cnt)

Solution (Python):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return set(divisors)


def is_dividable(x, d_set):
    for d in d_set:
        if x % d == 0 and d != 1:
            return True

    return False


a, b = map(int, input().split(' '))
divs_a = make_divisors(a)
divs_b = make_divisors(b)

common_div = [x for x in divs_a if x in divs_b]
common_div.sort()

seq = set()
for x in common_div:
    if not is_dividable(x, seq):
        seq.add(x)


print(len(seq))

Solution (Python):
import fractions

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

gcd_ab=fractions.gcd(a,b)

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

soinnsuu=factorization(gcd_ab)

if gcd_ab == 1:
    ans=1
else:
    ans=len(soinnsuu)+1

print(ans)

Solution (Python):
import fractions 
import random

A, B = list(map(int, input().split()))
C = fractions.gcd(A,B)
cnt = 1
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
    return divisors

def is_prime(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False

    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)

        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False

    return True

D = make_divisors(C)
for i in D:
    if is_prime(i) == True:
        cnt += 1
print(cnt)

Solution (Python):

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        if 2 not in a:
            a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f not in a:
                a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


inputNum = list(map(int, input().split()))

resultA = prime_factorize(inputNum[0])
resultB = prime_factorize(inputNum[1])

print(len(set(resultA) & set(resultB)) + 1)

Solution (Python):












import math

A, B = [int(i) for i in input().split(" ")]

def solve(n):
    ans, i = [], 1
    while i * i <= n:
        div, mod = divmod(n, i)
        if mod == 0:
            ans.append(i)
            if i != div:
                ans.append(div)
        i += 1
    return list(sorted(ans))  

a = solve(A)
b = solve(B)
c = list(sorted(set(a) & set(b)))


ans = []
for i in c:
   for a in ans:
       if a == 1: continue
       if i % a == 0:
          break
   else:
      ans.append(i) 

print(len(ans))

Solution (Python):
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a, b = map(int, input().split())
pa, pb = set(prime_factorize(a)), set(prime_factorize(b))
print(len(list(pa & pb))+1)

Solution (Python):

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

def GCD(M, N):
  if M > N:
    L = N
    N = M
    M = L
  m, n = M, N
  r = n % m
  while r != 0:
    n = m
    m = r
    r = n % m
  return(m)

def factorize(N):
  b = 2
  fct = []
  while b ** 2 <= N:
    while N % b == 0:
      N //= b
      fct.append(b)
    b += 1
  if N > 1:
    fct.append(N)
  return(fct)

key = set(factorize(GCD(A, B)))

print(len(key) + 1)