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):
A , B = map(int, input().split())
def gcd(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp
    r = x % y   
    while r != 0:
        x = y
        y = r
        r = x % y
    return y
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
X = gcd(A,B)
lst = make_divisors(X)
for i in lst:
    if i == 1:
        check = [1]
        continue
    for j in check:
        if gcd(i, j) != 1:
            break
    else:
        check.append(i)
print(len(check))

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


ans = 1 
chk_a = a
chk_b = b
if((a % 2) == 0 and (b % 2) == 0):
    ans += 1
while chk_a % 2 == 0:
    chk_a //= 2
while chk_b % 2 == 0:
    chk_b //= 2
f = 3
checker = max(a, b)
while f * f <= checker:
    if( (chk_a % f) == 0 and (chk_b % f) == 0):
        ans += 1
    while chk_a % f == 0:
        chk_a //= f
    while chk_b % f == 0:
        chk_b //= f
    f += 2
check_min = min(chk_a,chk_b)
if((chk_a % check_min) == 0 and (chk_b % check_min) == 0 and check_min > 1):
    ans += 1
print(ans)

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

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

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

c = set(make_divisors(a))
d = set(make_divisors(b))
e = list(c & d)

f = []
for i in range(len(e)):
        if is_prime(e[i]):
            f.append(e[i])
print(len(f) + 1)

Solution (Python):
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

A_temp = make_divisors(A)
B_temp = make_divisors(B)

AB_temp = list(set(A_temp) & set(B_temp))

ans = 0

for i in AB_temp:
    count = 0
    if i > 2 and i % 2 != 0:
        for j in AB_temp:
            if i % j != 0:
                count += 1
        if count == len(AB_temp)-2:
            ans += 1
    elif i <= 2:
        ans += 1
 
print(ans)

Solution (Python):
x,y = 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)
    return divisors
x_li=(make_divisors(x))
y_li=(make_divisors(y))
z_li=(list(set(x_li)&set(y_li)))

 
import math
count=1

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
for n in z_li:
  if(is_prime(n)==True):
    count=count+1
print(count)

Solution (Python):
a1,a2 = map(int,input().split())
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
import collections
c1 = collections.Counter(prime_factorize(a1))
c1 = list(c1.keys())
c2 = collections.Counter(prime_factorize(a2))
c2 = list(c2.keys())
c = 1
for i in range(0,len(c1)):
    if c2.count(c1[i]) == 0:
        continue
    else:
        c = c+1
print(c)

Solution (Python):
import math

def euclid(a, b):
    if a == b:
        return a
    elif b > a:
        return euclid(b, a)
    else:
        while b > 0:
            temp = a % b
            a = b
            b = temp
        return a


def get_e(x):
    l = []
    i = 2
    m = math.floor(math.sqrt(x))
    while i <= m and i <= x:
        if x % i == 0:
            x = x // i
            l += [i]
        else:
            i += 1
    if x != 1:
        l += [x]
    return l


def calc(A, B):
    gcd = euclid(A, B)
    if gcd == 1:
        return 1
    else:
        return 1 + len(set(get_e(gcd)))


(A, B) = tuple([int(s) for s in input().split(' ')])
print(calc(A, B))

Solution (Python):


def main():
    from fractions import gcd
    A, B = map(int, input().split())
    
    if B > A:
        A, B = B, A
    G = gcd(A, B)
    print(1+len(set(prime_factorize(G))))

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
main()

Solution (Python):


''' 
------------------------
author : iiou16
------------------------
'''

def main():
    A, B = list(map(int, input().split()))

    
    a = max(A, B)
    b = min(A, B)
    while b:
        a, b = b, a % b
    

    
    def prime_decomposition(n):
        i = 2
        table = []
        while i * i <= n:
            while n % i == 0:
                n /= i
                table.append(i)
            i += 1
        if n > 1:
            table.append(n)
        return table

    pp = prime_decomposition(a)
    

    
    ans = len(set(pp)) + 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
    
        if not is_prime[i]:  
            continue
            """
            bool(not False)はTrueになる
            """
        for j in range(i * 2, n + 1, i):
        
            is_prime[j] = False
            
    return [i for i in range(n + 1) if is_prime[i]]
     


def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


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


A_divs = []
ans = 0

for i in range(1, int(A**(1/2))+2):
    if A % i == 0:
        A_divs.append(i)
        A_divs.append(A//i)

common_divisor = []

for a in A_divs:
    if B % a == 0:
        common_divisor.append(a)

common_divisor = list(set(common_divisor))
common_divisor.sort()


ans = [1]

for num in common_divisor:
    flag = True
    for i in range(len(ans)):
        if gcd(num, ans[i]) != 1:
            flag = False
    if flag:
        ans.append(num)
ans.remove(1)

print(len(ans))

Solution (Python):


import fractions
n, k  = map(int, input().split())
l=[]



kou=fractions.gcd(n, k)


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
    
    
l = prime_factorize(kou)

print(len(set(l))+1)

Solution (Python):
from collections import defaultdict as dd
from fractions import gcd
L = 10**6+1
isPrime = [True] * L
isPrime[0] = False
isPrime[1] = False
primes = []
for n in range(2, L):
  if isPrime[n]:
    primes.append(n)
    isPrime[2*n::n] = [False] * ((L-n-1) // n)

def primeFactorization(n):
  ret = dd(int)
  ret[1] = 1
  for p in primes:
    while n % p == 0:
      ret[p] += 1
      n //= p
  ret[n] = 1
  return ret

A, B = map(int, input().split())
g = gcd(A, B)
ps = primeFactorization(g)
print(len(ps))

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

import math

def prime(n):
  if n == 1:
    return False
  i = 1
  while i < int(math.sqrt(n)):
    i += 1
    if n%i == 0:
      return False
  else:
    return True



if prime(a) and prime(b) and a==b:
  print(2)
  exit()
  
if a-b == 1 or b-a == 1:
  print(1)
  exit()

l = []
for i in range(1, max(int(math.sqrt(a))+2, int(math.sqrt(b))+2)):
  if i == 1:
    l.append(i)
  else:
    if a%i == 0 and b%i == 0 and prime(i):
      l.append(i)
    j = a//i
    if j != 0:
      if b%j == 0 and prime(j):
        l.append(j)
    k = b//i
    if k != 0:
      if a%k == 0 and prime(k):
        l.append(k)

print(len(set(l)))

Solution (Python):
def main():
    a, b = map(int, input().split(' '))
    d_s = make_divisors(a, b)

    ans = []

    for j in d_s:
        flg = True
        for k in d_s:
            if k == 1 or j == k:
                continue
            if j % k == 0:
                flg = False
                break
        if flg:
            ans.append(j)
    print(len(ans))


def make_divisors(a, b):
    A = []
    B = []
    n = max(a, b)
    for i in range(1, int(n**0.5)+1):
        if a % i == 0:
            A.append(i)
            if i != a // i:
                A.append(a//i)
        if b % i == 0:
            B.append(i)
            if i != b // i:
                B.append(b//i)
    return list(set(A) & set(B))


if __name__ == '__main__':
    main()

Solution (Python):
a, b = map(int, input().split())
import math
import fractions
n = fractions.gcd(a, b)
devide = 2
l1 = []
while devide <= math.sqrt(n):
    while n % devide == 0:
        n = n / devide
        l1.append(devide)
    devide += 1
l1.append(n)
l1 = list(set(l1))
if n == 1:
    print(int(len(l1)))
else:
    print(int(len(l1) + 1))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    def gcd(x, y):
        while y:
            x, y = y, x % y
        return x

    def soin(x):
        res = []
        cnt = 0
        while x % 2 == 0:
            x //= 2
            cnt += 1
        if cnt: res.append(cnt)
        d = 3
        while d ** 2 <= x:
            cnt = 0
            while x % d == 0:
                x //= d
                cnt += 1
            if cnt: res.append(cnt)
            d += 2
        if x != 1: res.append(1)
        return res

    a, b = map(int, input().split())
    g = gcd(a, b)
    e = soin(g)
    print(len(e) + 1)

main()

Solution (Python):
import itertools


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
    
A, B = map(int, input().split())
    
com_div = sorted(list(set(make_divisors(A)) & set(make_divisors(B))))


limit = max(com_div)**0.5 + 1

primes = []

for i in itertools.count(1):
    if i >= len(com_div):
        break
    sosuu = com_div[i]
    if sosuu > limit:
        break
    com_div = [j for j in com_div if (j % sosuu != 0 or j == sosuu)]

print(len(com_div))

Solution (Python):
import math
from fractions import gcd

def era(ps, n):
    if len(ps) == 1:
        return 1
    search_list = ps[1:]
    for i in range(1, n+1):
        search_list = [num for num in search_list if num % i != 0 or num == i ]

    return len(search_list)+1

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

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

    
    return divisors

def main():
    a,b = map(int, input().split())

    g = gcd(a, b)
    div = make_divisors(g)
    

    ans = 1
    for n in div:
        if is_prime(n):
            ans += 1

    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
import fractions
a,b=map(int, input().split())
f=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 f==1:
  print(1)
  exit()
else:
  temp=factorization(f)
  temps=set([])
  for item in temp:
    temps.add(item[0])
  if 1 in temps:
    print(len(temps))
  else:
    print(len(temps)+1)

Solution (Python):
import math
def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 
  
a,b = map(int,input().split())
n = gcd(a,b)
count = [1]
while (n % 2 == 0):
    count += [2]
    n = n / 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
    while (n % i == 0):
        count+=[i]
        n = n / i

if n > 2:
    count+=[n]
c = 1
count = sorted(count)
for i in range(1,len(count)):
    if (count[i-1] != count[i]):
        c+=1
print(c)

Solution (Python):

import math


def trial_division(n):
    factor_set = set()
    factor_set.add(1)
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor_set.add(num)
    if not factor_set:
        factor_set.add(n)
        return factor_set
    else:
        factor_set.add(n)
        return factor_set


a, b = map(int, input().split())
td_a = trial_division(a)
td_b = trial_division(b)
count = len(td_a & td_b)
print(count)

Solution (Python):
def main():
    A, B = map(int, input().split())
    X = prime_decomposition(gcd(A, B))
    print(len(set(X))+1)


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


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


if __name__ == '__main__':
    main()

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) 
n = 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)

    
    return divisors
  
L = sorted(make_divisors(n))
tmp = []
for i in range(len(L)):
  e = L[i]
  if e == 1:
    tmp.append(e)    
  else:
    f = 0
    for j in range(len(tmp)):      
      if gcd(e,tmp[j]) != 1:
        f = 1
        if tmp[j] == 1:
          f = 0
    if f == 0:
      tmp.append(e)

print(len(tmp))

Solution (Python):
import math
def g(a, b):
    if b == 0:
        return a
    else:
        if a < b:
            a, b = b, a
        return g(b, a % b)


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

t = g(A, B)

k = 2
cnt = 0
while t > 1:
    limit = int(math.sqrt(t))
    if k > limit + 1:
        break
    if t % k == 0:
        cnt += 1
        while t % k == 0:
            t //= k
    k += 1
if not t == 1:
    cnt += 1
print(cnt + 1)

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

length = int(A ** 0.5) + 2
Ax = A
s = [1] * length
ans, i, lim, t = 1, 2, A ** 0.5, set()
while i < lim:
    if s[i] == 1:
        for j in range(i*2, length, i):
            s[j] = 0
        if A % i == 0:
            if B % i == 0:
                ans += 1
            while Ax % i == 0:
                Ax //= i
    i += 1

if Ax >= length and B % Ax == 0:
    ans += 1
print(ans)

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

def gcd(x, y):
    if y== 0:
        return x
    else:
        return gcd(y, x % y)

X = 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

temp = make_divisors(X)
ans = []
ans.append(temp[0])
if len(temp) >= 2:
    ans.append(temp[1])

for i in range(2, len(temp)):
    for a in ans:
        if gcd(temp[i], a) != 1:
            break
    else:
        ans.append(temp[i])

print(len(ans))

Solution (Python):
import numpy as np
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 np.array(arr)

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

a = factorization(A)
b = factorization(B)

ans = 1+len(list(set(a[:,0])&set(b[:,0])))
if A==B and A==1:
  ans=1
print(ans)

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)

    
    return divisors

aa = make_divisors(a)
bb = make_divisors(b)

aaa = list(set(aa) & set(bb))

al = len(aaa)
count = 0



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


for i in range(al):
  if is_prime(aaa[i]):
    count += 1

print(count+1)

Solution (Python):
import math
import sys
import itertools
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a,b = IL()
num = int(math.sqrt(max(a,b)))
Ayakusuu = []
Byakusuu = []
ansl = []
ans = 0

numA = int(math.sqrt(a))
for i in range(1,numA+1):
  if a%i == 0:
    Ayakusuu.append(i)
    Ayakusuu.append(a//i)


numB = int(math.sqrt(b))
for i in range(1,numB+1):
  if b%i == 0:
    Byakusuu.append(i)
    Byakusuu.append(b//i)

yakusuu = set(Ayakusuu) & set(Byakusuu)

for i in yakusuu:
  num2 = int(math.sqrt(i))
  for k in range(2,num2+1):
    if i%k == 0:
      break
  else:
    ansl.append(i)

for i in range(len(ansl)):
  for j in range(len(ansl)):
    if i == j:
      continue
    else:
      aa, bb = ansl[i], ansl[j]
      if aa == 1:
        continue
      else:
        num3 = min(aa,bb)
        for k in range(2,num3+1):
          if aa%k == 0 and bb%k == 0:
            break
        else:
          continue
        break
  else:
    ans += 1



print(ans)


"""
for i in itertools.combinations(ansl, 2):
  print(i)
  aa, bb = i
  if aa == 1:
    ans += 1
  else:
    num3 = min(aa,bb)
    for k in range(2,num3+1):
      if aa%k == 0 and bb%k == 0:
        break
    else:
      ans += 1


print(ansl)
print(ans)
"""

Solution (Python):



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 __name__ == "__main__":
    Input1 = [input() for i in range(1)]
    
    A,B = list(map(int,Input1[0].split()))
    if B > A:
        temp = A
        A = B
        B = temp

    ans = 1
    if B == 1:
        print(ans)
    else:
        fact = factorization(B)
        for i in range(len(fact)):
            f = fact[i][0]
            if A % f == 0:
                ans += 1
        print(ans)

Solution (Python):
from math import sqrt


def IsPrime(num):
    if num < 2:
        return True
    elif num == 2:
        return True
    elif num % 2 == 0:
        return False

    sqrtNum = sqrt(num)
    for i in range(3, int(sqrtNum) + 1, 2):
        if num % i == 0:
            return False

    return True


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

    
    return divisors


if __name__ == "__main__":
    A, B = map(int, input().split())

    A_list = make_divisors(A)
    B_list = make_divisors(B)

    AB_list = set(A_list) & set(B_list)

    ans = list()
    for i in AB_list:
        if IsPrime(i):
            ans.append(i)

    print(len(ans))

Solution (Python):
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)
    return divisors

comdiv = [] 
div = make_divisors(A)
for i in div:
  if B % i == 0:
    comdiv.append(i)


def isPrime(n):
  if n < 2:
    return False
  i = 2
  while i*i <= n:
    if n%i == 0:
      return False
    i += 1
  return True

cnt = 0
for i in comdiv:
  if isPrime(i):
    cnt += 1
print(cnt+1)

Solution (Python):
import fractions

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

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 = set(prime_factorize(A))
b = set(prime_factorize(B))
c = a & b

print(len(c) + 1)

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


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

g = gcd(a,b)


arr = []
temp = g
for i in range(2, int(-(-g**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])

print(len(arr)+1)

Solution (Python):
def factorization(n):
    arr = []
    Cnt = 0
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            if i not in arr:
                Cnt += 1
                arr.append(i)

    if temp!=1 and temp not in arr:
        Cnt += 1
        arr.append(temp)




    return Cnt


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

if a < b:
    a, b = b, a
while a % b != 0:
    a, b = b, a % b

N = factorization(b)

print(N+1)

Solution (Python):
words = lambda t : list(map(t, input().split()))
a,b = words(int)

def gcd(x,y):
    while not y == 0:
        tmp = y
        y = x%y
        x = tmp
    return x

import math
def num_prime_factors(n):
    cnt = 0
    m = int(math.sqrt(n)) + 1
    for num in range(2,m):
        if n % num == 0:
            cnt += 1
            while n % num == 0:
                n //= num
    if not n == 1:
        cnt += 1
    return cnt

g = gcd(a,b)
cnt = num_prime_factors(g)
print(cnt+1)

Solution (Python):
import math

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

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

    return True

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
    
a, b = map(int, input().split())

set1 = set(make_divisors(a))


set2 = set(make_divisors(b))


set3 = set1 & set2


count = 0
for n in set3:
    
    if is_prime(n):
        
        count += 1

print(count)

Solution (Python):
import math


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


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


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

a_div = list(make_divisors(a))
a_div_pri = []
for num in a_div:
    if is_prime(num):
        a_div_pri.append(num)

a_div_pri.append(1)
ans = 0
for num in a_div_pri:
    if b % num == 0:
        ans += 1

print(ans)

Solution (Python):

import copy
import math
A,B = map(int, input().split())

num = min(A,B)
tmps = {}
p = 2
for p in range(2, math.ceil(num**0.5)+1):

    if A % p == 0 and B % p == 0:
        tmps[p] = True

    if A % (num//p) == 0 and B % (num//p) == 0:
        tmps[num//p] = True

    p += 1

if num != 1 and  A % num == 0 and B % num == 0:
    tmps[num] = True


d = copy.deepcopy(tmps)
for k in tmps.keys():

    if d.get(k, False):
        aaa = copy.deepcopy(d)
        for n in d.keys():
            if k == n:
                continue
            if n > k and n % k == 0:
                aaa.pop(n)
        d = aaa

print(len(d.keys())+1)

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

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

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

c = set(make_divisors(a))
d = set(make_divisors(b))
e = list(c & d)

f = []
for i in range(len(e)):
        if is_prime(e[i]):
            f.append(e[i])
print(len(f) + 1)

Solution (Python):

from fractions import gcd
import itertools
import sys
input = sys.stdin.readline



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



def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass


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


def main():
    A, B = map(int, input().split())
    
    da = sorted(divisor(A))
    db = sorted(divisor(B))
    cd = []
    for i in da:
        if i in db:
            cd.append(i)

    
    li = []
    
    for i in cd:
        if i == 1:
            li.append(i)
            continue

        flg = True
        for c in li:
            if not coprime(i, c):
                flg = False

        if flg:
            li.append(i)

    
    print(len(li))


if __name__ == '__main__':
    main()

Solution (Python):
a,b=map(int,input().split())
if a<b:
  a,b=b,a
def gcd(m,n):
  while n!=0:
    m,n=n,m%n
  return m
def div(l):
  division=[]
  for i in range(1,int(l**0.5)+1):
    if l%i==0:
      division.append(i)
      if i!=(l//i):
        division.append(l//i)
  return division
lst=div(gcd(a,b))
cnt=1
for i in range(len(lst)):
  if len(div(lst[i]))==2:
    cnt+=1
print(cnt)

Solution (Python):
def find_lcd(A,B):
  if A==1 or B==1:
    return 1
  if A==B:
    return A
  else:
    return find_lcd(min(A,B), abs(A-B))
  
def find_num_prime(X):
  if X==1:
    return 1
  count = 1 
  i=2
  sqrt_org=int(X**0.5)
  while X != 1:
    if i**2 > X:
      count += 1
      break
    if X%i == 0:
      count += 1
      while X%i == 0:
        
        X = int(X/i)
    if i== 2:
      i += 1
    else:
      i += 2
  return count
  
A,B = map(int, input().split())
lcd=find_lcd(A,B)

print(find_num_prime(lcd))

Solution (Python):
from fractions import gcd
import copy


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


def main():
    A, B = [int(i) for i in input().split()]

    A_l = divisor(A)
    B_l = divisor(B)
    AB_l = set()
    for a in A_l:
        if a in B_l:
            AB_l.add(a)
    AB_l = sorted(list(AB_l))
    tmp = set(AB_l)
    ans = []
    for i, a in enumerate(AB_l):
        if a not in tmp:
            continue
        try:
            tmp.remove(a)
        except:
            pass
        for b in list(tmp):
            if gcd(a, b) != 1:
                try:
                    tmp.remove(b)
                except:
                    pass
        else:
            ans.append(a)

    print(len(ans))


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


if __name__ == "__main__":
    main()

Solution (Python):
from fractions import gcd

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


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


ad, bd = divisor(A), divisor(B)
xs = list(sorted(ad & bd))

ans = [1]
for x in xs:
    flag = True
    for k in ans:
        if gcd(x, k) != 1:
            flag = False
            break
    if flag:
        ans.append(x)
print(len(set(ans)))

Solution (Python):
from math import sqrt

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


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

if M == 1:
    print(1)
    exit()

res = []
x = M
y = 2
while y*y <= x:
    while x % y == 0:
        res.append(y)
        x //= y
    y += 1
if x > 1:
    res.append(x)

ans = set(res)
print(len(ans)+1)

Solution (Python):
a,b = map(int,input().split())
from fractions import gcd
max = gcd(a,b) 
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

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

div_list = make_divisors(max)

count = 1
for i in range(len(div_list)):


    if is_prime(div_list[i]):
        count += 1

print(count)

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())
A_factors=prime_factorize(A)
B_factors=prime_factorize(B)
B_factors = set(B_factors)
A_factors = set(A_factors)
C = A_factors & B_factors
ans = len(C) + 1
print(ans)

Solution (Python):
from fractions import gcd
import heapq

a,b = (int(i) for i in 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

D = make_divisors(gcd(a,b))
j = {d:True for d in D}

heapq.heapify(D)
ans = []
ans.append(heapq.heappop(D))

for _ in range(len(D)):
    tmp = heapq.heappop(D)
    if j[tmp] == True:
        for d in D:
            if gcd(tmp,d) != 1: j[d] = False
        ans.append(tmp)

print(len(ans))