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

if a==1 or b==1:
    print(1)
    exit()

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_prime=prime_factorize(a)
b_prime=prime_factorize(b)

a_prime=set(a_prime)
b_prime=set(b_prime)

ans=0
for i in a_prime:
    if i in b_prime:
        ans+=1

print(ans+1)

Solution (Python):
import math
a,b = (int(x) for x in input().split())
saidai = 1

def yakusuu(x,y):
    return(y,x % y)

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

saidai = math.gcd(a,b)


d = cont(saidai)
if d[0] == [1,1]:
    print(1)
    exit()
print(len(d) + 1)

Solution (Python):
import  math

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


def prime_factorization(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

C = math.gcd(A, B)




print(len(set(prime_factorization(C))) + 1)

Solution (Python):
A, B = [int(x) for x in input().split()]

def prime_factorization(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

Aprimes = prime_factorization(A)
Bprimes = set(prime_factorization(B))

ans = 1
ansset = set()
for a in Aprimes:
    if a in ansset:
        continue
    if a in Bprimes:
        ansset.add(a)
        ans += 1

print(ans)

Solution (Python):

from math import gcd
def resolve():
    def prime_factorize(n):
        if 2 <= n < 4:
            return [n]
        res = []
        i = 2
        while i * i <= n:
            while n % i == 0:
                res.append(i)
                n //= i
            i += 1
        if n != 1:
            res.append(n)

        return set(res)

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

    g = gcd(a, b)
    ans = prime_factorize(g)
    print(len(ans) + 1)


if __name__ == "__main__":
    resolve()

Solution (Python):
def factorize(n):
    if n == 1:
        return
    
    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
            if i in fact:
                fact[i] = 1
            else:
                fact[i] = 0
         
    if tmp != 1:
        if tmp in fact:
            fact[tmp] = 1
        else:
            fact[tmp] = 0
    
    if len(fact) == 0:
        if N in fact:
            fact[N] = 1
        else:
            fact[N] = 0

A, B = list(map(int, input().split()))
fact = {}

factorize(A)
factorize(B)

cnt = 1

for val in fact.values():
    if val == 1:
        cnt += 1

print(cnt)

Solution (Python):
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


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





def LI(): return list(map(int, sys.stdin.buffer.readline().split()))




def I(): return int(sys.stdin.buffer.readline())





def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()




def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')







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







def SRL(n): return [list(S()) for i in range(n)]


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def main():
    a, b = LI()
    ans = 1
    a_div = make_divisors(a)

    for div in a_div:
        if a == 1 or b == 1:
            break
        if div == 1:
            continue
        if b % div == 0:
            ans += 1
            while b % div == 0:
                b /= div
        while a % div == 0:
            a /= div
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def factorize(n):
    fct = set()
    b,e = 2,0
    while b*b <= n:
        while n % b == 0:
            n //= b
            e += 1
        if e > 0:
            fct.add(b)
        b,e = b+1,0
    if n > 1:
        fct.add(n)
    return fct
a,b = map(int,input().split())
print(len(factorize(a)&factorize(b))+1)

Solution (Python):
def factorize(n):
    fct = set()
    b,e = 2,0
    while b*b <= n:
        while n % b == 0:
            n //= b
            e += 1
        if e > 0:
            fct.add(b)
        b,e = b+1,0
    if n > 1:
        fct.add(n)
    return fct
a,b = map(int,input().split())
print(len(factorize(a)&factorize(b))+1)

Solution (Python):
def factorize(n):
    fct = []
    b,e = 2,0
    while b*b <= n:
        while n % b == 0:
            n //= b
            e += 1
        if e > 0:
            fct.append((b,e))
        b,e = b+1,0
    if n > 1:
        fct.append((n,1))
    return fct
a,b = map(int,input().split())
ap = set()
for prime,count in factorize(a):
    ap.add(prime)
bp = set()
for prime,count in factorize(b):
    bp.add(prime)
print(len(ap&bp)+1)

Solution (Python):
import math

a,b = map(int,input().split())
x = math.gcd(a,b)
s = [1]
for i in range(2,int(math.sqrt(x)+1)):
    if x%i == 0:
        while x%i == 0:
            x //= i
        s.append(i)
if x != 1:
    s.append(x)
l = len(s)
print(l)

Solution (Python):
from functools import lru_cache

def main():
    a,b=map(lambda x: set(prime_factorize(int(x))),input().split())
    print(len(a&b)+1)

@lru_cache(maxsize=None)
def primes(n:int) -> list:
    '''n以下の全素数をlistで返す'''
    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
        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]]


@lru_cache(maxsize=None)
def is_prime(n: int) -> bool:
    '''引数nが素数であればTrue、そうでなければFalseを返す'''
    if n == 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    for i in range(3, int(n**0.5)+1, 2):
        if n % i == 0:
            return False
    return True


@lru_cache(maxsize=None)
def prime_factorize(n: int) -> list:
    '''引数nの素因数分解結果のlistを返す。'''
    arr = []
    
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    
    for f in primes(int(n**0.5)):
        while n % f == 0:
            arr.append(f)
            n //= f
    if n != 1:
        arr.append(n)
    return arr


def make_divisors(n: int) -> list:
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
        
if __name__ == "__main__":
    main()

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

from math import gcd

a, b = map(int,input().split())
g = gcd(a,b)
if g == 1:
    print(1)
else:
    print(len(factorization(g))+1)

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    def factorization(n):
        if n==1:
            return []
        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
    
    mod=10**9+7
    a,b=MI()
    from math import gcd
    g=gcd(a,b)
    arr=factorization(g)
    
    ans=len(arr)+1
    
    print(ans)
    
    
    

main()

Solution (Python):
import math        







def fctr1(n): 
    f = []
    c = 0
    r = int(n**0.5)
    for i in range(2,r+2):
        while n%i == 0:
            c += 1 
            n = n//i
        if c != 0:
            f.append([i,c])
            c = 0
    if n != 1:
        f.append([n,1])
    return f

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

print(len(fctr1(math.gcd(a,b)))+1)

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


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


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

print(len(factorization(gcd(a,b)))+1 if gcd(a,b)!=1 else 1)

Solution (Python):
from math import gcd
A, B = map(int, input().split())
def factorize(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

n = gcd(A, B)
ans = factorize(n)
if ans[0][0] == 1:
    print(1)
    exit()
print(len(ans)+1)

Solution (Python):
import math
def gcd(a,b):
    if a==0: return b
    return gcd(b%a,a)
def div(n):
    cnt = 0
    temp = n
    for i in range(2,int(math.sqrt(n))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            cnt += 1
    if temp!=1:
        cnt+=1
    return cnt+1

a,b = map(int,input().split())
print(div(gcd(a,b)))

Solution (Python):
import math
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())
Af = factorization(A)
Bf = factorization(B)
As = set()
Bs = set()
for i in range(len(Af)):
    As.add(Af[i][0])
for j in range(len(Bf)):
    Bs.add(Bf[j][0])
if A == 1 and B ==1:
    print(1)
else:
    print(len(As & Bs)+1)

Solution (Python):
a,b=map(int,input().split())
def 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 set(a)
print(len(factorize(a)&factorize(b))+1)

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

cnt = 0
for i in A:
    if i in B:
        cnt += 1
print(cnt+1)

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

plist = []

for i in range(2, int(g ** 0.5) + 1):
	if g % i == 0:
		plist.append(i)
		while(g % i == 0):
			g //= i
if g != 1:
	plist.append(g)

print(len(plist) + 1)

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

def fact(x):
	temp = x
	arr = [1]
	for i in range(2, int(math.sqrt(x))):
		if temp % i == 0:
			c = 0
			while temp % i == 0:
				c += 1
				temp //= i
			arr.append(i)
	if temp != 1:
		arr.append(temp)
	if arr == []:
		arr.append(n)
	return arr

a = fact(A)
b = fact(B)
ans = 0
for i in a:
	if i in b:
		ans += 1


print(ans)

Solution (Python):





def gcd(a, b):
    """最大公約数"""
    a, b = (a, b) if a >= b else (b, a)
    if b == 0:
        return a
    return gcd(b, a % b)


def prime_factorization(x):
    """素因数分解"""
    import math
    re = []
    i = 2
    while x != 1:
        if x % i == 0:
            re.append(i)
            x //= i
        else:
            i += 1
            if i > math.sqrt(x):
                re.append(x)
                break
    return re






def solve(A, B):
    div = gcd(A, B)
    print(len(set(prime_factorization(div))) + 1)


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

Solution (Python):


import math

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


def count_prime_factorize(n):
    res = 1
    i = 2
    while i ** 2 <= n:
        if n % i == 0:
            res += 1
            while n % i == 0:
                n //= i
        i += 1
    if n != 1:
        res += 1
    return res


a, b = map(int, input().strip().split())
x = gcd(a, b)
res = count_prime_factorize(x)
print(res)

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

from math import sqrt
from math import gcd
a, b = map(int, input().split())
x = gcd(a, b)
print(len(set(prime_factorize(x)))+1)

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)

    divisors.sort()
    return divisors


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

lst=make_divisors(a)
sin_lst=[]

for i in lst:
  if b%i==0:
    sin_lst.append(i)

if len(sin_lst)==1:
  print(1)
  exit()

lst=[]
lst.append(sin_lst[1])

for i in sin_lst[2:]:
  flag=True
  for j in lst:
    if i%j==0:
      flag=False
      break
  
  if  flag:
    lst.append(i)


print(len(lst)+1)

Solution (Python):
import fractions
import sys
sys.setrecursionlimit(10**9)


INF=10**20
def prime_factorize(n):
    P = []
    P_set = set()
    while n % 2 == 0:
        P.append(2)
        P_set.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            P.append(f)
            P_set.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        P.append(n)
        P_set.add(n)

    P_count = {p:0 for p in P_set}
    for p in P: P_count[p] += 1

    return P_count


def solve(A: int, B: int):
    gcd = fractions.gcd(A,B)
    P = prime_factorize(gcd).keys()
    print(len(list(P))+1)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    solve(A, B)



if __name__ == "__main__":
    main()

Solution (Python):
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
a, b = map(int, input().split())
n = gcd(a, b)
primes = []
MAX = 10 ** 6 + 10
is_prime = [False] * 2 + [True] * (MAX - 2)
for i in range(2, MAX):
    if is_prime[i]:
        primes.append(i)
        for j in range(i * i, MAX, i):
            is_prime[j] = False
cnt = 1
for p in primes:
    if n % p == 0:
        cnt += 1
        while n % p == 0:
            n /= p
if n != 1:
    cnt += 1
print(cnt)

Solution (Python):
import math

A, B = [int(_) for _ in input().split()]
N = math.gcd(A, B)

ans = 1
for i in range(2, int(math.sqrt(N)+1) + 1):
    if N % i == 0:
        ans += 1
        while N % i == 0:
            N //= i
if N > 1:
    ans += 1
print(ans)

Solution (Python):
a,b=map(int,input().split())
if a==1 and b==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
ans=0
A=factorization(a)
B=factorization(b)
for i in A:
  for j in B:
    if i[0]==j[0]:
      ans+=1
print(ans+1)

Solution (Python):
from fractions import gcd
A, B = map(int, input().split())
g = gcd(A, B)
ans = 1
n = 2
while g > 1:
  if n * n > g:
    ans += 1
    break
  if g % n == 0:
    ans += 1
  while g % n == 0:
    g //= n
  n += 1
print(ans)

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

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

p = gcd(a, b)
factors = {}

while p > 1:
    f = False
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            if i in factors:
                factors[i] += 1
            else:
                factors[i] = 1

            p //= i
            f = True
            break

    if not f:
        if p in factors:
            factors[p] += 1
        else:
            factors[p] = 1
        break

print(len(factors)+1)

Solution (Python):
import sys
import math
import itertools
import collections
from collections import deque
 
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
 
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
 
def main():
    A, B = NMI()
    GCD = math.gcd(A, B)
    N=GCD
    
    cnt = 0
    
    ls=[]
    
    for n in range(2,int(N**0.5)+2):
 
        if GCD % n == 0:
            cnt += 1
 
            while GCD % n == 0:
                GCD = GCD//n
                ls.append(n)
        
    if GCD == 1:
        print(cnt+1)
    else:
        print(cnt+2) 

if __name__ == '__main__':
    main()

Solution (Python):
import math

def divisors(x):
    l = [[], []]
    for i in range(1, int(math.sqrt(x))+1):
        if x % i == 0:
            if i**2 != x:
                l[0].append(i)
                l[1].append(x//i)
            else:
                l[0].append(i)
    return l[0]+l[1][::-1]

def primenumber(x):
    for i in range(2, int(math.sqrt(x))+1):
        if x % i == 0:
            return False
    return True

a, b = map(int, input().split())
cnt = 0
for i in divisors(math.gcd(a, b)):
    if i == 1:
        cnt += 1
    elif primenumber(i):
        cnt += 1
print(cnt)

Solution (Python):
from math import gcd
import random
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


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


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

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())
l = make_divisors(gcd(A, B))
_l = factorization(gcd(A, B))
ans = 0



for num in l:
    if is_prime3(num):
        
        ans += 1
print(ans + 1)

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


def gcd(A,B):
    while B!=0:
        A,B=B,A%B
    return A


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

print(len(factorization(gcd(a,b)))+1 if a!=1 and b!=1 else 1)

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


def gcd(A,B):
    while B!=0:
        A,B=B,A%B
    return A


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

print(len(factorization(gcd(a,b)))+1 if a!=1 and b!=1 else 1)

Solution (Python):





def main():
  A,B = map(int,input().split())
  def primeLst(x):
    acc = []
    f = 2
    while f * f <= x:
      if x % f == 0:
        acc.append(f)
        x //= f
      else:
        f += 1
    if x != 1:
      acc.append(x)
    return acc
  a = set(primeLst(A))
  b = set(primeLst(B))
  if len(a) * len(b) == 0:
    ans = 1
  else:
    ans = len(a&b) + 1
  print(ans)
  return

if __name__ == '__main__':
  main()

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

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

cnt = len(set(prime_decomposition(x)))

print(cnt+1)

Solution (Python):
a,b=map(int,input().split())
import math
c=math.gcd(a,b)
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
print(len(set(prime_factorize(c)))+1)

Solution (Python):
def factrization(n):
    arr = []
    temp = n
    
    for i in range(2, int(n**0.5//1) + 2):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            arr.append(i)
    
    if temp != 1:
        arr.append(temp)
    
    if arr == []:
        arr.append(n)
    
    return arr

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

la = factrization(a)
lb = factrization(b)

if 1 not in la:
    la.append(1)
if 1 not in lb:
    lb.append(1)

for i in la:
    if i in lb:
        ans += 1

print(ans)

Solution (Python):
import math

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

n=math.gcd(a,b)

cnt=1

f=2
d=n
while f*f<=n:
    if d%f==0:
        cnt+=1
        while d%f==0:
            d=d//f
    f+=1
if d!=1:
    cnt+=1

print(cnt)

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7

import numpy

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

c = math.gcd(A, B)
d = factorization(c)

if c > 1:
    print(len(d)+1)
else:
    print(1)

Solution (Python):
import math

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

cnt = len(set(prime_decomposition(t)))

print(cnt+1)

Solution (Python):
a,b=map(int,input().split())
A=[1]
for i in range(2,int(a**0.5)+1):
    if a%i==0:
        while a%i==0:
            a//=i
        A.append(i)
if a>1:
    A.append(a)
B=[1]
for i in range(2,int(b**0.5)+1):
    if b%i==0:
        while b%i==0:
            b//=i
        B.append(i)
if b>1:
    B.append(b)
can=0
for i in A:
    if i in B:
        can+=1
print(can)

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

def fact(n):
    k = 2
    l = [] 
    temp=n
    while pow(k, 2)<=n:
        if temp%k==0:
            l.append(k)
            while temp%k==0:
                temp//=k
        k+=1
    if temp!=1:
        l.append(temp)
    return l

if A==1 and B==1:
    print(1)
elif A==B:
    print(len(set(fact(A)))+1)
else:
    print(len(set(fact(A))&set(fact(B)))+1)

Solution (Python):
import math

def enum_div(n):
    ir=int(n**(0.5))+1
    ret=[]
    for i in range(1,ir):
        if n%i == 0:
            ret.append(i)
            if (i!= 1) & (i*i != n):
                ret.append(n//i)
    return ret

def isPrime(x):
    if x < 2:
        return 0
    elif x == 2:
        return 1
    if x%2 == 0:
        return 0
    ir=int(x**(0.5))+1
    for i  in range(3,ir,2) :
        if x%i == 0:
            return 0
    return 1

a,b=map(int,input().split())
c=math.gcd(a,b)

if isPrime(c)==1:
    print(2)
else:
    icnt=0
    for i in enum_div(c):
        if isPrime(i)==1:
            icnt+=1
    print(icnt+1)

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

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


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

t = factorization(gcd(a,b))
if t[0][0]==1:
    print(1)
    exit()
print(len(t)+1)

Solution (Python):
import math


def main():
    a, b = map(int, input().split())
    gcd = math.gcd(a, b)
    ans = [1]
    while gcd % 2 == 0:
        ans.append(2)
        gcd = gcd // 2
    f = 3
    while f * f <= gcd:
        if gcd % f == 0:
            ans.append(f)
            gcd = gcd // f
        else:
            f += 2
    if gcd != 1:
        ans.append(gcd)
    print(len(set(ans)))


if __name__ == '__main__':
    main()

Solution (Python):
import math 
def using_sqrt(k):  
    factor = 0
        
    
    if k % 2 == 0 and k != 2:
        return False
        
    
    for divisor in range(2, math.floor(math.sqrt(k))+1):
        if k % divisor == 0:
            factor += 1
                
    if factor == 0:
        return True
    else:
        return False
            
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 make_codivisors(n):
    divisors = []
    n0divisors = make_divisors(n[0])
    n0len = len(n0divisors)
    for i in n0divisors:
        for j in range(1, len(n)):
            if n[j] % i != 0:
                break
            if j == len(n)-1:
                divisors.append(i)
            
    
    return divisors

a, b =map(int, input().split())
div = make_codivisors([a, b])
ans = 0
for i in div:
  if i==1:
    ans+=1
  else:
    if using_sqrt(i):
      ans+=1
print(ans)

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

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

Gcd = gcd( A , B )
lo_cds = []
up_cds = []
i = 1
while i * i <= Gcd:
    if Gcd % i == 0:
        lo_cds.append(i)
        if Gcd // i != i:
            up_cds.append( Gcd // i )
    i += 1
Cds = lo_cds + up_cds[::-1]

Cds.pop(0)
i = 0


while i < len(Cds):
    j = i + 1
    while j < len(Cds):
        if Cds[j] % Cds[i] == 0:
            Cds.pop(j)
        else:    
            j += 1
    i += 1

print( len(Cds) + 1 )

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

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

gcd = math.gcd(A,B)
d = []
if A == 1 or B == 1 :
    print(1)
    exit()
ans = [1]
while gcd %2 == 0 :
    gcd //= 2
    ans.append(2)
i = 3
while i * i <= gcd :
    if gcd %i == 0 :
        ans.append(i)
        gcd //= i
    else :
        i += 2
if gcd != 1 :
    ans.append(gcd)
print(len(set(ans)))