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 bunkai(x):
    x_set = set()
    for i in range(1, int(x**0.5)+2):
        if x % i == 0:
            x_set.add(i)
            x_set.add(x//i)
    return x_set

def is_prime(x):
    for i in range(2, int(x**0.5)+1):
        if x % i == 0:
            return None
    ans.add(x)

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

A_set = bunkai(A)
B_Set = bunkai(B)
kari = A_set & B_Set

ans = set()
for x in kari:
    is_prime(x)
print(len(ans))

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

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

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

from fractions import gcd
from collections import defaultdict
import math
def factorize(n):
    d = defaultdict(int)

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

ab = gcd(A, B)
d = factorize(ab)
print(len(d) + 1)

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 = []
    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())
tmp = make_divisors(a)
divisors = []
for d in tmp:
  if b%d==0:
    divisors.append(d)

arr = []
for d in divisors:
  if d==1:
    arr.append(1)
  elif is_prime(d):
    arr.append(d)
print(len(arr))

Solution (Python):


def main():
    a, b = map(int, input().split())
    c = gcd(a, b)
    pf = prime_factor(c)
    pfu = set(pf)
    print(len(pfu) + 1)

def gcd(x, y):
    if x < y:
        x, y = y, x  
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

def prime_factor(n):
    resid = n
    result = []
    i = 2
    while True:
        if resid <= 1:
            return result
        if i ** 2 > resid:
            result.append(resid)
            return result
        if resid % i == 0:
            result.append(i)
            resid /= i
        else:
            i += 1

if __name__ == "__main__":
    main()

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

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

n = fractions.gcd(A, B)
if n == 1:
    print(1)
    sys.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


a = {x[0] for x in factorization(A)}
b = {x[0] for x in factorization(B)}

print(len(a & b) + 1)

Solution (Python):

from collections import defaultdict as dd
A,B = map(int,input().split())

def get_p(n):
    th = round(n**0.5)
    ans = (n,1)
    for i in range(2,th+1):
        if n % i ==  0:
            ans = (i,n//i)
            break
    return(ans)
            
def get_yakusu(n):
    flag = 1
    pn_dic = dd(lambda: 0)
    while flag:
        yaku,red = get_p(n)
        if yaku == n:
            pn_dic[str(yaku)] += 1
            flag = 0
        else:
            pn_dic[str(yaku)] += 1
            n = red
    return(pn_dic)

apn_dic = get_yakusu(A)
apn_dic["1"] += 1
bpn_dic = get_yakusu(B)
bpn_dic["1"] += 1





kouyaku_dic = dd(lambda:0)

wa_key = list(set(apn_dic.keys()) & set(bpn_dic.keys()))

for key in wa_key:
    kouyaku_dic[key] = min(apn_dic[key],bpn_dic[key])


    
m = len(wa_key)
        
print(m)

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

C=1
A,B=map(int,input().split())
a=factorization(A)
b=factorization(B)
for i in range(len(a)):
 a[i][1]=0
for i in range(len(b)):
 b[i][1]=0
for i in range(len(a)):
 if a[i] in b:
  if a[i][0]>1:
   C+=1
print(C)

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

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

g=fractions.gcd(A, B)

lst=factorize(g)

print(1+len(set(lst)))

Solution (Python):
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, B = lr()
g = 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

G = prime_factorize(g)

used = set([1])
for x in G:
    for y in used:
        if gcd(x, y) != 1:
            break
    else:
        used.add(x)

print(len(used))

Solution (Python):
import copy
a,b=map(int,input().split())
s1=set()
s2=set()
for i in range(1,int(a**0.5)+1):
  if a%i==0:
    s1.add(i)
    s1.add(a//i)
for i in range(1,int(b**0.5)+1):
  if b%i==0:
    s2.add(i)
    s2.add(b//i)
s=s1&s2
l=sorted(list(s))
for i in range(1,len(l)):
  for j in range(i+1,len(l)):
    if l[j]%l[i]==0 and l[j] in s:
      s.remove(l[j])
print(len(s))

Solution (Python):

import math


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


def prime_fact(x):
    prime_pow = {}
    check_ceil = math.ceil(math.sqrt(x))
    for p in range(2, check_ceil + 1):
        p_cnt = 0
        while x % p == 0:
            x //= p
            p_cnt += 1
        if p_cnt:
            prime_pow[p] = p_cnt
    if x > 1:
        prime_pow[x] = 1
    return prime_pow


def submit():
    a, b = map(int, input().split())
    g = gcd(a, b)
    
    p = prime_fact(g)
    print(len(p) + 1)


if __name__ == "__main__":
    submit()

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

A = []
B = []

for i in range(1, int(a**0.5) + 1):
    if a % i == 0:
        A.append(i)
        A.append(a//i)
for j in range(1, int(b**0.5) + 1):
    if b % j == 0:
        B.append(j)
        B.append(b//j)

C = set(A) & set(B)


D = []


def uni(x):
    for i in range(1, int(x**0.5)+1):
        if x % i == 0 and i != 1:
            return False
    return True


for i in C:
    if uni(i):
        D.append(i)
print(len(D))

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_div=make_divisors(a)
b_div=make_divisors(b)
ab_div=a_div+b_div
ab_div.sort()
ab=[]
for i in range(len(ab_div)-1):
    if ab_div[i] == ab_div[i+1]:
        ab.append(ab_div[i])

ans=[ab[0]]
for i in range(1,len(ab)):
    
    jagh=1
    for j in range(1,len(ans)):
        if ab[i]%ans[j] == 0:
            break
    else:
        
        ans.append(ab[i])
print(len(ans))

Solution (Python):


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

    a,b = map(int, input().split())
    
    def prime_decomp(n):
        i = 2
        res = []
        while i ** 2 <= n:
            while n % i==0:
                n //= i
                res.append(i)
            i += 1
        if n > 1:
            res.append(n)
        return res

    c = set(prime_decomp(a))
    d = set(prime_decomp(b))
    print(len(c&d)+1)


if __name__ == '__main__':
    main()

Solution (Python):


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

    a,b = map(int, input().split())
    
    def prime_decomp(n):
        i = 2
        res = []
        while i ** 2 <= n:
            while n % i==0:
                n //= i
                res.append(i)
            i += 1
        if n > 1:
            res.append(n)
        return res

    c = set(prime_decomp(a))
    d = set(prime_decomp(b))
    print(len(c&d)+1)


if __name__ == '__main__':
    main()

Solution (Python):
def factorize(a: int) -> dict:
    """素因数分解 O(sqrt(N))
    return 素因数のdict
    """
    ps = {}
    i = 2
    nokori = a
    while i*i <= nokori:
        if nokori % i == 0:
            cnt = 0
            while nokori % i == 0:
                cnt += 1
                nokori //= i
            ps[i] = cnt
        i += 1
    if nokori != 1:
        ps[nokori] = 1
    return ps


A, B = map(int, input().split())
factor_of_a = factorize(A).keys()
factor_of_b = factorize(B).keys()
ans = len(set(factor_of_a) & set(factor_of_b))
ans += 1  
print(ans)

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


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


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

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

def prime_factorize(n):
    s = set()
    while n % 2 == 0:
        s.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            s.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        s.add(n)
    return s
print(1+len(prime_factorize(c)))

Solution (Python):

import fractions
import math
a, b = map(int,input().split())
ans = 0
g = 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

ans = len(factorization(g)) + 1
if a == 1 or b == 1:
    ans = 1
print(ans)

Solution (Python):
from fractions import gcd

a,b = [int(x) for x in input().split()]

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

z = gcd(a,b)
print(len(prime_factor(z)))

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

n = fractions.gcd(A,B)
print(len(set(prime_factorize(n)))+1)

Solution (Python):
from fractions import gcd

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)

    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)

    return arr
  
a = factorization(a)
b = factorization(b)
if (len(a)==1 and a[0] == 1) or (len(b)==1 and b[0] == 1):
  print(1)
else:
  print(len(set(a) & set(b)) + 1)

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

base=fractions.gcd(A,B)
count=1


for i in range(2,int(pow(base,1/2)+1)):
    if base==1:
        break
    else:
        if base%i==0:
            count+=1
            while base%i==0:
                base//=i
if base!=1:
    count+=1
print(count)

Solution (Python):
import math
from fractions import gcd

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

'''
g = gcd(a, b)

for i in range(1, g+1):
    if a % i == 0 and b % i == 0:
        cd.add(i)
        '''

i =  1
a_set = set()

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

i = 1
b_set = set()

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

cd = set(a_set) & set(b_set)

for s in sorted(list(cd)):
    if s == 1:
        ans.add(s)
    else:
        for t in sorted(list(ans)):
            if t == 1:
                continue
            elif s % t == 0:
                break
        else:
            ans.add(s)

print(len(ans))

Solution (Python):
import math
import time
from collections import deque
from collections import defaultdict
from copy import deepcopy

mod = 10 ** 9 + 7
t = time.time()



def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def main():
    A, B = iip()

    a = set(soinsuu_bunkai(A))
    b = set(soinsuu_bunkai(B))

    ans = 1 
    for aa in a:
        if aa in b:
            ans+=1

    print(ans)

main()

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

a_div = []
b_div = []

i = 1
while i * i < a + 1:
    if a % i == 0:
        a_div.append(i)
        a_div.append(a // i)
    i += 1
i = 1
while i * i < b + 1:
    if b % i == 0:
        b_div.append(i)
        b_div.append(b // i)
    i += 1

common = set(a_div) & set(b_div)

disjoint = set()
for num in sorted(list(common)):
    if num == 1:
        disjoint.add(num)
    else:
        for disnum in sorted(list(disjoint)):
            if disnum == 1:
                continue
            elif num % disnum == 0:
                break
        else:
            disjoint.add(num)

print(len(disjoint))

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


fa = set([x for x, y in factorization(a)]+[1])
fb = set([x for x, y in factorization(b)]+[1])
ans = 0
for x in fa:
    if x in fb:
        ans += 1
print(ans)

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

def gcd(x, y):
    '''
    最大公約数の計算
    '''
    if y == 0:
        return x
    return gcd(y, x % y)

G = gcd(A, B)



def prime_factorize(n):
    res, a = [], 2
    while a*a <= n:
        if n % a == 0:
            ex = 0
            while n % a == 0:
                ex += 1
                n //= a
            res.append((a, ex))
        a += 1
    if n != 1:
        res.append((n, 1))
    return res

prime = prime_factorize(G)

print(len(prime)+1)

Solution (Python):

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
A,B = list(map(int,input().split()))

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

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

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

    return arr

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

Solution (Python):
A,B = (int(i) for i in input().split())

import math

def trial_division(n):
    
    factor = [1]
    
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    
    factor.append(n)
    return factor

A_ = trial_division(A)
B_ = trial_division(B)
c = list(set(A_))
d = list(set(B_))

count = 0
for i in range(len(c)):
    for j in range(len(d)):
        if c[i] == d[j]:
            count += 1

print(count)

Solution (Python):
from collections import defaultdict

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


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


d = gcd(A, B)



def f(v):
    dic = defaultdict(int)
    if v == 1:
        dic[1] = 1
        return dic
    for i in range(2, v):
        if i * i > v:
            break
        while v % i == 0:
            v //= i
            dic[i] += 1
    if v != 1:
        dic[v] += 1
    dic[1] = 1
    return dic


divisor = f(d)

print(len(divisor))

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

def is_prime(q, k=5):
    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())
comNum = list(set(make_divisors(a)) & set(make_divisors(b)))
ans = 1
for i in comNum:
    if is_prime(i):
        ans += 1
print(ans)

Solution (Python):

from fractions import gcd
a, b = map(int, input().split())
ab = gcd(a, b)

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

    if tmp != 1:
        arr.append(tmp)

    if arr == []:
        arr.append(n)

    return arr

print(len(factorization(ab)))

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

faca=fac(a)
facb=fac(b)

Fa=set()
Fb=set()
for i in faca:
      Fa.add(i[0])
for i in facb:
      Fb.add(i[0])
Fu=Fa&Fb
if a==1 or b==1:
      print(1)
else:
      print(len(Fu)+1)

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

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

ans = 1

g = gcd(A, B)

for i in range(2, 1 + int(sqrt(g))):

    if g % i == 0:
        ans += 1

        while g % i == 0:
            g //= i

if g != 1:
    ans += 1

print(ans)

Solution (Python):
def prime_pair(n):
    pairs = {}
    tmp = n
    for i in range(2, n):
        if i * i > n:
            break
        if tmp % i != 0:
            continue
        ex = 0
        while tmp % i == 0:
            ex += 1
            tmp /= i
        pairs[i] = ex
    if tmp != 1:
        pairs[int(tmp)] = 1
    return pairs

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


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

ppa = prime_pair(A)
ppb = prime_pair(B)

g = gcd(A,B)
ppg = prime_pair(g)

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

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

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

dl = list(set(make_divisors(a)) & set(make_divisors(b)))
dl.sort(reverse = True)


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

del dl[dl.index(1)]
ans = [1]
flag=True
j=0
while(j<len(dl)):
    x = dl.pop(0)
    for i in dl:
        if gcd(x,i)==1:
            next
        else:
            flag=False
            break
    if flag:
        ans.append(x)
    flag=True
print(len(ans))

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

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 main():
    A, B = map(int, input().split())

    ap = prime_factorize(A)
    bp = prime_factorize(B)

    primes = [1] + list(set(ap) & set(bp))

    print(len(primes))


if __name__ == "__main__":
    main()

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

Solution (Python):
from fractions import gcd
a, b = [int(i) for i in input().split()]
c = gcd(a, b)

def p(x):
    a=[]
    i=2
    while True:
        if x % i == 0:
            j=0
            while x % i == 0:
                x //= i
                j += 1
            a.append((i, j))
        if i * i > x:
            break
        i += 1
    if x != 1:
        a.append((x,1))
    return a

print(len(p(c))+1)

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


def prime_factorization(n):
    res = []
    for i in range(2, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            ex = 0
            while n % i == 0:
                ex += 1
                n //= i
            res.append([i, ex])
    if n != 1:
        res.append([n, 1])
    return res


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

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

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
ans=0
for x in set(make_divisors(A))&set(make_divisors(B)):
  if is_prime(x):
    ans+=1


print(ans+1)

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

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

print(len(prime_factorize(AB))+1)

Solution (Python):
def prefactor(x):
  ret = set()
  for i in range(2, int(x**0.5)+1):
    if x%i==0: ret.add(i)
    while x%i==0: x //= i
  if x>1: ret.add(x)
  return ret
    

a, b = map(int, input().split())
print(1+len(prefactor(a) & prefactor(b)))

Solution (Python):
def decomposition_prime(n):
    i = 2
    li = []
    while i*i <= n:
        while n%i == 0:
            li.append(i)
            n /= i
        i += 1
    if n > 1:
        li.append(int(n))
    return li

a, b = map(int, input().split())
ap = decomposition_prime(a)
bp = decomposition_prime(b)

print(len(set(ap) & set(bp))+1)

Solution (Python):

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

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

arr=[i for i in a if i in b]
print(len(arr)+1)

Solution (Python):

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

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

arr=[i for i in a if i in b]
print(len(arr)+1)

Solution (Python):
import math

def Sieve_of_Eratosthenes(N):
    if N<2:
        prime = [False for i in range(N+1)]
        return prime
 
    prime = [True for i in range(N+1)]
    prime[0] = False
    prime[1] = False
 
    for i in range(2, int(N**0.5)+1):
        if prime[i]:
            for j in range(i*2, N+1, i):
                prime[j] = False
 
    return prime


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

a,b=map(int,input().split())
n=gcd(a,b)
prime=Sieve_of_Eratosthenes(int(math.sqrt(n))+2)
ans=1
x=n
for p in range(len(prime)):
    if prime[p]:        
        if x==1:
            break
        if x%p==0:
            ans+=1
            while x%p==0:
                x=x//p

if x!=1: ans+=1
print(ans)

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

C = gcd(A, B)


def prime_factorize(n):
    a = {}
    while n % 2 == 0:
        a[2] = True
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] = True
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] = True
    return a

print(len(prime_factorize(C)) + 1)

Solution (Python):



X, Y = map(int, input().rstrip().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
    
print(1 + len(set(prime_factorize(X)) & set(prime_factorize(Y))))

Solution (Python):
import math
from collections import defaultdict


def trial_division(n):
    factor = defaultdict(int)
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            factor[num] += 1
    factor[n] += 1
    if 1 not in factor.keys():
        factor[1] += 1
    return factor


a, b = map(int, input().split())
ans = 0
for i in trial_division(a).keys():
    if i in trial_division(b).keys():
        ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from fractions import gcd
import collections

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 main():
    a,b=map(int,input().split())
    g=gcd(a,b)
    print(len(set(prime_factorize(g)))+1)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

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

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

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

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


def factorization_in_prime_number(x):
    prime_factor = []
    if x % 2 == 0:
        prime_factor.append(2)
    while x % 2 == 0:
        x //= 2
    m = int(x**.5) + 1
    for i in range(3, m, 2):
        if x % i == 0:
            prime_factor.append(i)
        while x % i == 0:
            x //= i
    if x != 1:
        prime_factor.append(x)
    
    return prime_factor


a_factor = factorization_in_prime_number(a)
b_factor = factorization_in_prime_number(b)
ans = len(set(a_factor) & set(b_factor)) + 1
print(ans)

Solution (Python):
A,B = map(int,input().split())
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

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

c = 1
for i in range(len(a)):
    for j in range(len(b)):
        if a[i][0] == b[j][0]:
            if a[i][0] != 1:
                c += 1

print(c)

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


def factorization_in_prime_number(x):
    prime_factor = []
    if x % 2 == 0:
        prime_factor.append(2)
    while x % 2 == 0:
        x //= 2
    m = int(x**.5) + 1
    for i in range(3, m, 2):
        if x % i == 0:
            prime_factor.append(i)
        while x % i == 0:
            x //= i
    if x != 1:
        prime_factor.append(x)
    return prime_factor


a_factor = factorization_in_prime_number(a)
b_factor = factorization_in_prime_number(b)
ans = len(set(a_factor) & set(b_factor)) + 1
print(ans)

Solution (Python):
def prime_factorize(n):
    res = []
    while n % 2 == 0:
        res.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            res.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        res.append(n)
    return res
from fractions import gcd
a, b = map(int, input().split())
print(len(set(prime_factorize(gcd(a, b))))+1)