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 prime_factor(n):
    factors = []
    for i in range(2, int(n**0.5)+1):
        count = 0
        while n % i == 0:
            count += 1
            n /= i
        if count != 0:
            factors.append((i, count))
    if n != 1:
        factors.append((n, 1))
    return factors
a, b = map(int, input().split())
apf = prime_factor(a)
bpf = prime_factor(b)
print(len(set(i[0] for i in apf)&set(i[0] for i in bpf))+1)

Solution (Python):
import math
A, B = map(int, input().split())
if B < A:
    A, B = B, A
a = []
while A % 2 == 0:
    a.append(2)
    A //= 2
f = 3
while f * f <= A:
    if A % f == 0:
        a.append(f)
        A //= f
    else :
        f += 2
if A != 1:
    a.append(A)
ans = 0
for i in set(a):
    if B % i == 0:
        ans += 1
print(ans+1)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a,b = map(int,input().split())
def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        count=0
        while n % i==0:
            count+=1
            n = n//i
        if count!=0:
            ass.append((i,count))
    if n != 1:
        ass.append((n,1))
    return ass
def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a
    
def lcm(m,n):
    return (m*n)//gcd(m,n)

ab = gcd(a,b)
primes = prime_factor(ab)
print(len(primes)+1)

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


def prime_factorization(n):
    from collections import Counter
    counter = Counter()

    if n < 2:
        return counter

    for i in range(2, int(n ** 0.5) + 1):
        if i * i > n:
            break

        while n % i == 0:
            counter[i] += 1
            n //= i

    if n > 1:
        counter[n] += 1

    return counter


x = prime_factorization(A)
y = prime_factorization(B)

z = set(x.keys()) & set(y.keys())
print(len(z) + 1)

Solution (Python):


import fractions


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


A, B = map(int, input().split())
C = fractions.gcd(A, B)
if A==1 or B==1:
    print(1)
elif C==1:
    print(1)
else:
    arr = factorization(C)
    print(len(arr) + 1)

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

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def primeCount(N):
    R = int(N**(0.5)) + 1  
    primes = {}  
    n = N
    for num in range(2, R):
        primes[num] = 0
        while n % num == 0:
            n //= num
            primes[num] += 1
    if n > 1 :
        primes[n] = 1
    return { key : val for key, val in primes.items() if val > 0}  

G = gcd(A, B)
P = primeCount(G)

ans = 1 + len(P.keys())
print(ans)

Solution (Python):
import math
A, B = map(int,input().split())
def yakusuu(N):
    P = set([1,N])
    for k in range(2,math.floor(math.sqrt(N))+1):
        if N % k == 0:
            P.add(k)
            P.add(N//k)
    return P
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
C = sorted(list(yakusuu(A)&yakusuu(B)))
N = len(C)
if N == 1:
    print(1)
else:
    ans = 0
    for k in range(N):
        f = 1
        for l in range(k):
            if gcd(C[k],C[l]) != 1:
                f = 0
                break
        ans += f
    print(ans)

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

def mygcd(a, b):
    if a < b:
        return mygcd(b, a)
    elif b == 0:
        return a
    else:
        return mygcd(b, a % b)

gcd = mygcd(A, B)

import math

pfac = {}
gcd_tmp = gcd
for p in range(2, int(math.sqrt(gcd)) + 1):
    if gcd_tmp < 2: break
    if gcd_tmp % p == 0:
        i_p = 0
        while gcd_tmp % p == 0:
            gcd_tmp //= p
            i_p += 1
        
        pfac[str(p)] = i_p
else:
    if gcd_tmp > 1: pfac[str(gcd_tmp)] = 1
    

        
print(1 + len(pfac))

Solution (Python):
import math
A,B=map(int,input().split())
X=math.sqrt(min(A,B))
L=[]
for i in range(1,int(X)+1):
	if A%i==0:
		L.append(i)
		L.append(A//i)
L=set(L)
L=sorted(L)
S=[]
for i in L:
	if B%i==0:
		S.append(i)
ans=1
for i in S:
	if i==1:continue
	count=0
	for j in range(2,int(math.sqrt(i))+1):
		if i%j==0:
			count+=1
			break
	if count==0:
		ans+=1
print(ans)

Solution (Python):
from fractions import gcd
A, B = map(int, input().split())
g = gcd(A, B)

from collections import Counter

def factorize(n):
  d = Counter()
  m = 2
  while m*m <= n:
    while n%m == 0:
      n //= m
      d[m] += 1
    m += 1
  if n > 1:
    d[n] += 1
  return d

fs = factorize(g) 
print(len(fs) + 1)

Solution (Python):
def make_prime_factors_compress(n: int):
    """自然数nの素因数を列挙した圧縮済みリストを出力する
    計算量：O(sqrt(N))
    入出力例：156 -> [(2, 2), (3, 1), (13, 1)]
    """
    prime_factors = []
    for k in range(2, int(n**0.5) + 1):
        cnt = 0
        while n % k == 0:
            cnt += 1
            n = n // k
        if cnt != 0:
            prime_factors.append((k, cnt))
    if n != 1:
        prime_factors.append((n, 1))
    return prime_factors

def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


def lcm(a: int, b: int) -> int:
    """a, bの最小公倍数(least common multiple: LCM)を求める
    計算量: O(log(min(a, b)))
    """
    return (a * b) // gcd(a, b)

  
a, b = map(int, input().split())
gcd_ = gcd(a, b)
print(len(make_prime_factors_compress(gcd_)) + 1)

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

import fractions
g = fractions.gcd(a, b)

import math

def div(m):
    d = {}
    temp = int(math.sqrt(m))+1
    for i in range(2, temp):
        while m%i== 0:
            m //= i
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
    if d == {}:
        d[m] = 1
    else:
        if m in d:
            d[m] += 1
        elif m != 1:
            d[m] =1
    return d

d = div(g)

if 1 not in d:
    ans = len(d)+1
else:
    ans = 1
print(ans)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(n):
        res = set([1])
        i = 2
        m = n
        while i**2 <= n:
            while m%i == 0:
                res.add(i)
                m //= i
            i += 1
        res.add(m)
        return res

    a,b = LI()
    fa = f(a)
    fb = f(b)
    l = fa&fb
    print(len(l))
    return


if __name__ == "__main__":
    solve()

Solution (Python):
from fractions import gcd
A,B = map(int,input().split())
g = gcd(A,B)

from collections import Counter
def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d

fs = factorize(g)

print(len(fs) + 1)

Solution (Python):
from fractions import gcd
a, b = map(int,input().split())

GCD = gcd(a,b)
ans = 1
for i in range(2, int(GCD ** 0.5) + 1):
    if GCD%i == 0:ans += 1
    while GCD%i == 0:
        GCD //= i
if GCD != 1:ans += 1
print(ans)

Solution (Python):
a,b = map(int,input().split())
from fractions import gcd
import math
ab_gcd = gcd(a,b)
def trial_division(n):
    
    factor = []
    
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    
    if not factor:
        return [1,n]
    else:
        factor.append(n)
        return factor
res = trial_division(ab_gcd)
print(len(set(res+[1])))

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

def pf(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

aa = set(pf(a))
bb = set(pf(b))
ans = aa & bb

print(len(ans) + 1)

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

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

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 gcd == 1:
    print(1)
else:
    ans = len(factorization(gcd)) + 1
    print(ans)

Solution (Python):
import math
import collections


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]


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

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

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

    
a,b=MI()
g=gcd(a,b)
pg=list(set(prime_factorize(g)))
print(len(pg)+1)

Solution (Python):


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




def prime_factorize(n):
    
    res = []
    for i in range(2,n+1):
        
        ex = 0
        
        if i * i > n:
            break
        if n % i != 0:
            continue
        
        while ( n % i == 0):
            ex += 1
            n /= i
        
        res.append([i,ex])
    
    if n != 1:
        res.append([int(n),1])

    return res

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


G = gcd(A,B)


pf = prime_factorize(G)


print(len(pf) +1)

Solution (Python):
a, b = map(int, input().split())
import fractions
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
if a == 1 or b == 1:
    print(len(factorization(gcd)))
    quit()
print(len(factorization(gcd)) + 1)

Solution (Python):
from fractions import gcd
from math import sqrt


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


def main():
    A, B = map(int, input().split())
    C = gcd(A, B)
    if (A == 1 or B == 1):
        print(1)
        exit(0)
    if (C == 1):
        print(1)
        exit(0)
    arr = factorization(C)
    
    print(len(arr) + 1)


if __name__ == "__main__":
    main()

Solution (Python):
from fractions import gcd
from math import sqrt


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


def main():
    A, B = map(int, input().split())
    C = gcd(A, B)
    if (C == 1):
        print(1)
        exit(0)
    arr = factorization(C)
    
    print(len(arr) + 1)


if __name__ == "__main__":
    main()

Solution (Python):
def factrize(x):
    f = {}
    if x == 1:
        return f
    tmp = x
    i = 2
    while i**2 <= tmp:
        cnt = 0
        while tmp % i == 0:
            cnt += 1
            tmp = tmp//i
        if cnt > 0:
            f[i] = cnt
        i += 1
    if tmp != 1 or f == {}:
        f[tmp] = 1
    return f

from fractions import gcd
A, B= map(int, input().split())
G = gcd(A, B)
dict = factrize(G)
print(1+len(dict))

Solution (Python):
import fractions
A,B = map(int,input().split())
GCD = fractions.gcd(A,B)
if GCD == 1:
    print(1)
    exit()
    
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

Bunkai = factorization(GCD) 
print(len(Bunkai) + 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)
	
	return divisors

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

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





g = gcd(a,b)

bunkai = factorization(g)

if len(bunkai) == 1 and bunkai[0][0] == 1:
	print(1)
else:
	print(len(bunkai) + 1 )

Solution (Python):
from fractions import gcd
A,B=map(int,input().split())
x=gcd(A,B)
prime=set()
prime.add(1)
for i in range(2,int(x**0.5)+1):
    while x%i==0:
        prime.add(i)
        x//=i
if x!=1:
    prime.add(x)
print(len(prime))

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

def is_prime(q,k=50):
    q = abs(q)
    
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True
  
A,B = map(int,input().split())

g = fractions.gcd(A,B)
l = make_divisors(g)
su = 1
for li in l:
  if is_prime(li):
    su+=1
    
print(su)

Solution (Python):


import sys
import math

















def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
                

    from fractions import gcd
    a, b = mi()
    g = gcd(a, b)
    

    n = int(math.sqrt(g) + 1)
    table = [True for _ in range(n)]
    table[0] = False
    table[1] = False
    
    primes = [2]
    for p in range(3, n, 2):
        if table[p]:
            primes.append(p)
            for i in range(p**2, n, p):
                table[i] = False
    
    def calc_prime(num):
        cnt = 0
        
        
        for p in primes:
            if p > num:
                break
            if num % p == 0:
                cnt += 1
                while p <= num and num % p == 0:
                    num //= p
        if num != 1:
            cnt += 1    
        return cnt

    print(calc_prime(g)+1)    

if __name__ == "__main__":
    main()

Solution (Python):

def factorize(n):
    
    
    
    
    result = []
    tmp = n
    for k in range(2, int(n ** 0.5) + 1):
        cnt = 0
        while tmp % k == 0:
            cnt += 1
            tmp //= k
        if cnt > 0:
            result.append([k, cnt])
    if tmp != 1:
        result.append([tmp, 1])
    return result

def divisorize(n):
    
    
    
    f = factorize(n)
    divisors = [1]
    for k in range(len(f)):
        num_divisors = len(divisors)
        for i in range(1, f[k][1] + 1):
            for j in range(num_divisors):
                divisors.append(divisors[j] * f[k][0] ** i)
    return sorted(divisors)

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

da = factorize(a)
da = [1] + [k[0] for k in da]

db = factorize(b)
db = [1] + [k[0] for k in db]

i = set(da).intersection(db)

print(len(i))

Solution (Python):
import fractions

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

def md(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,B=map(int,input().split())
G=fractions.gcd(A,B)
Gd=md(G)
l=[]
ans=0
for g in Gd:
    if prime(g):
        l.append(g)
        ans+=1
print(ans)

Solution (Python):

A,B = (int(x) for x in input().split())


def soinsu_bunkai(m):
    pf={}

    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:
        pf[m]=1
    return pf

A_soinsu =soinsu_bunkai(A)
B_soinsu =soinsu_bunkai(B)


kyotu_soinsu ={}
a_sosu ={i for i in A_soinsu.keys()}
b_sosu ={i for i in B_soinsu.keys()}
kotae = a_sosu & b_sosu

print(len(kotae)+1)

Solution (Python):
import fractions
import math
from collections import Counter
a, b = map(int, input().split())
n = fractions.gcd(a, b)

prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(n))+1):
  while n % i == 0:
    n /= i
    prime_count[i] += 1
if n > 1:
  prime_count[int(n)] += 1

print(len(prime_count)+1)

Solution (Python):
def pf(n):
  a = []
  N = n
  for i in range(2, int(pow(N,0.5)//1+2)):
    if n%i==0:
      count=0
      while n%i==0:
        count+=1
        n//=i
      a.append(count)
  if n!=1:
    a.append(1)
  if a==[]:
    a.append(1)
  return a
import fractions
A,B=map(int,input().split())
c=fractions.gcd(A,B)
ans=len(pf(c))
print(ans+(1 if c>1 else 0))

Solution (Python):
A,B = map(int, input().split())
def cf(A,B):
    Af = []
    Bf = []
    for i in range(1,round(A**0.5)+1):
        if A % i == 0:
            Af.append(i)
            Af.append(A//i)
    for i in range(1,round(B**0.5)+1):
        if B % i == 0:
            Bf.append(i)
            Bf.append(B//i)
    cf = list(set(Af).intersection(Bf))
    return cf
L = cf(A,B)
ans = 0
def is_prime(n):
    cd = []
    for i in range(1,round(n**0.5)+1):
        if n % i == 0:
            cd.append(i)
    if cd == [1]:
        return True
    else:
        return False
for i in L:
    if is_prime(i):
        ans += 1
print(ans)

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations

input = sys.stdin.readline

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

ans = 1

for num in sorted(list(set(prime_factorize(a)))):
    if num in set(prime_factorize(b)):
        ans += 1

print(ans)

Solution (Python):
A,B = map(int,input().split())
def gcd(x,y):
    if x<y:x,y = y,x
    if y==0:return x
    return gcd(y,x%y)
G = gcd(A,B)
S = set()
S.add(1)
n = G
for i in range(2,G+1):
    if i*i>n:
        S.add(n)
        break
    if n%i==0:
        S.add(i)
    while n%i==0:
        n//=i
print(len(S))

Solution (Python):
import math
def trial_division(n):
    a = [1]
    for i in range(2,int(math.sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            a.append(i)
    a.append(n)
    return a

A, B = map(int, input().split())
print(len(set(trial_division(A))&set(trial_division(B))))

Solution (Python):
import math
from fractions import gcd

a,b = map(int,input().split())
g = gcd(a,b)
gr = int(math.ceil(math.sqrt(g)))

facs = [1]
i = 2
while i*i <= g:
    if g == 1:
        break
    if g % i == 0:
        facs.append(i)
        while g % i == 0:
            g //= i
    i += 1
if g != 1:
    facs.append(g)

print(len(facs))

Solution (Python):
from fractions  import gcd
a, b = map(int,input().split())
g = gcd(a,b)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 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
factors = factorization(g)
common_divide = [1] + [factor[0] for factor in factors]
total = len(common_divide)
if common_divide == [1,1]:
    total = 1
print(total)

Solution (Python):
import fractions
def factorization(n):
    arr=[]
    tmp=n
    for i in range(2,int(n**0.5)+1):
        if(tmp%i==0):
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
    arr.append([1,1])
    if(tmp!=1):
        arr.append([tmp,1])
    return arr
A,B=map(int,input().split())
g=fractions.gcd(A,B)
li=factorization(g)
print(len(li))

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

Solution (Python):
import fractions

def prime_function(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())
GCD=fractions.gcd(A,B)
print(len(set(prime_function(GCD)))+1)

Solution (Python):
from fractions import gcd
from collections import deque

a, b = map(int, input().split())
x = gcd(a, b)
y = int(x ** 0.5)
cd = deque([])
if x ** 0.5 % 1 == 0:
    cd.append(y)
    y -= 1
prime = []
for i in range(y, 0, -1):
    if x % i == 0:
        cd.appendleft(i)
        cd.append(x // i)

def prime_check(x, prime):
    for y in prime:
        if x % y == 0:
            return False
    return True

for x in cd:
    if prime_check(x, prime) and x != 1:
        prime.append(x)
print(len(prime) + 1)

Solution (Python):

"""
D - Disjoint Set of Common Divisors
https://atcoder.jp/contests/abc142/tasks/abc142_d

"""
import sys


from collections import defaultdict

def prime_factor(N):
    factors = defaultdict(int)
    for i in range(2, int(N**0.5)+1):
        while N % i == 0:
            factors[i] += 1
            N //= i
    if N != 1:
        factors[N] = 1

    return factors

def solve(A, B):
    pA = prime_factor(A)
    pB = prime_factor(B)
    res = [1]
    for k in pA.keys():
        if k in pB:
            res.append(k)
    return len(res)


def main(args):
    A, B = map(int, input().split())
    ans = solve(A, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
import fractions
a,b = map(int,input().split())
x = fractions.gcd(a,b)

def so(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
y = set(so(x))
print(len(y)+1)

Solution (Python):
import fractions
a,b=map(int,input().split())
g=fractions.gcd(a,b)
ans=1
i=2
while i*i<=g:
    if g%i==0:
        ans+=1
        while g%i==0:
            g//=i
    i+=1
if g>1:
    ans+=1
print(ans)

Solution (Python):
import random

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

a_divs = make_divisors(a)
b_divs = make_divisors(b)

a_b_divs = list(set(a_divs) & set(b_divs))
a_b_divs.sort()




def is_prime3(q,k=50):
    q = abs(q)
    
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

ans = 1
for j in a_b_divs:
    if is_prime3(j) == True:
        
        ans += 1

print(ans)

Solution (Python):
from fractions import gcd
from math import sqrt


def prime_factorize(n):
    result = []
    for i in range(2, int(sqrt(n)) + 1):
        if n % i != 0:
            continue
        t = 0
        while n % i == 0:
            n //= i
            t += 1
        result.append((i, t))
        if n == 1:
            break
    if n != 1:
        result.append((n, 1))
    return result


A, B = map(int, input().split())
print(len(prime_factorize(gcd(A, B))) + 1)

Solution (Python):
import math
from fractions import gcd

def factorization(n):
    arr = []
    tmp = n
    for div in range(2, int(math.sqrt(n)) + 2):
        if tmp % div == 0:
            cnt = 0
            while tmp % div == 0:
                cnt += 1
                tmp //= div
            arr.append([div, cnt])

    if tmp != 1:
        arr.append([tmp, 1])

    if len(arr) == 0:
        arr.append([n, 1])

    return arr

if __name__ == '__main__':
    A, B = map(int, input().split())
    g = gcd(A, B)
    if g == 1:
        print(1)
        exit()
    facts = factorization(g)
    print(len(facts) + 1)

Solution (Python):
import math

def divisors(n):
    s = set()
    for x in range(2, math.ceil(n ** 0.5) + 1):
        while n % x == 0:
            s.add(x)
            n /= x
            if n == 1:
                break
    if n > 1:
        s.add(n)
    return s
 
a, b = map(int, input().split())
d = divisors(a) & divisors(b)
print(len(d) + 1)

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

import fractions
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

if gcd == 1:
    print(1)
else:
    fact = factorization(gcd) 
    print(len(fact) + 1)

Solution (Python):
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import math
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

def main():
  A, B = map(int, readline().split())
  g = gcd(A, B)
  L = factorization(g)
  if L[0][0] == 1:
    ans = 1
  else:  
    ans = len(L) +1
  
  print(ans)
  
if __name__ == '__main__':
  main()

Solution (Python):
import fractions

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

g = fractions.gcd(a, b)

ans = 0
i = 2
while i * i <= g:
    if g % i == 0:
        ans += 1
        while g % i == 0:
            g //= i
    i += 1

if g > 1:
    ans += 1

print(ans + 1)