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



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

def prime_factorize(N):
    
    from collections import defaultdict
    factorize = defaultdict(int)
    while N%2 == 0:
        factorize[2]+=1
        N //= 2
    i=1
    while i*i <=N:
        i += 2
        if N%i: continue
        while N%i == 0:
            factorize[i] += 1
            N //= i
    if N!=1:factorize[N]=1
    return factorize

print(len(prime_factorize(abgcd).keys())+1)

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

A, B = map(int, input().split())
while A % B != 0:
	A, B = B, A % B
G = B
c = collections.Counter(prime_factorize(G))
print(len(list(c.keys())) + 1)

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	a,b = map(int,input().split())
	g = gcd([a,b])
	l = factorization(g)
	print(len(l)+1)

def factorization(n):
	if n<2:
		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

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

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

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(numbers):
	return reduce(fractions.gcd, numbers)

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

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

class PriorityQueue():
	def __init__(self):
		self.queue = []
	def push(self,i):
		heapq.heappush(self.queue,-i)
	def pop(self):
		return -1 * heapq.heappop(self.queue)
	def sum(self):
		return -sum(self.queue)

main()

Solution (Python):

from fractions import gcd
import copy

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

koyakusu = gcd(A, B)

yakusu_list = make_divisors(koyakusu)

rest = copy.deepcopy(yakusu_list)
ans = set()
count = 0

for v in yakusu_list:
    if v == 1:
        ans.add(1)
        continue
    if rest == []:
        break
    new_rest = []
    for r in rest:
        if r == 1:
            continue
        if r == v:
            ans.add(r)
            continue
        if r % v != 0:
            new_rest.append(r)
    rest = new_rest


print(len(ans))

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

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

al=factorization(a) 
bl=factorization(b)

a_s=set()
b_s=set()
for i in range(len(al)):
    a_s.add(al[i][0])
for j in range(len(bl)):
    b_s.add(bl[j][0])
    

s=a_s&b_s
s.add(1)    

print(len(s))

Solution (Python):

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

from fractions import gcd


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


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

ans = 0
gcd1 = gcd(A, B)
for i in divisor(gcd1):
    if is_prime(i):
        ans += 1

print(ans+1)

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

ans = [1]
while c % 2 == 0:
  ans.append(2)
  c //= 2
i = 3
while c >= i ** 2:
  if c % i == 0:
    ans.append(i)
    c //= i
  else:
    i += 2
if c != 1:
  ans.append(c)
print(len(set(ans)))

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

ans = [1]
while c % 2 == 0:
  ans.append(2)
  c //= 2
i = 3
while c >= i ** 2:
  if c % i == 0:
    ans.append(i)
    c //= i
  else:
    i += 2
if c != 1:
  ans.append(c)
print(len(set(ans)))

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


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

ans = []
while C % 2 == 0:
    ans.append(2)
    C //= 2
i = 3
while C >= i * i:
    if C % i == 0:
        ans.append(i)
        C //= i
    else:
        i += 2
if C != 1:
    ans.append(C)
print(len(set(ans)) + 1)

Solution (Python):

a,b = map(int,input().split())
while b > 0:
  a,b = b,a%b
prime = []
for i in range(2,int(a**.5)+1):
  if a % i == 0:
    p,q = i,0
    while a % i == 0:
      a //= i
      q += 1
    prime.append([p,q])
if a != 1:
  prime.append([a,1])
print(len(prime)+1)

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

lst1 = []
lst2 = []
A1,B1 = map(int, input().split(" "))

A = factorization(A1)
B = factorization(B1)

for i in range(len(A)):
    lst1.append(A[i][0])

for i in range(len(B)):
    lst2.append(B[i][0])



lst1_set = set(lst1)
lst2_set = set(lst2)

result_set = lst1_set & lst2_set



if A1 == 0 or B1 == 0:
    print(0)
elif A1 == 1 and B1 == 1:
    print(1)
else:
    print(len(result_set) + 1)

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

from fractions import gcd
g = gcd(A,B)

a = [1]
while g % 2 == 0:
    a.append(2)
    g //= 2
f = 3
while f * f <= g:
    if g % f == 0:
        a.append(f)
        g //= f
    else:
        f += 2
if g != 1:
    a.append(g)

print(len(set(a)))

Solution (Python):
import math 
import fractions
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
A,B=map(int,input().split())
counter=0
gcd=fractions.gcd(A,B)
c = collections.Counter(prime_factorize(gcd))
print(len(c)+1)

Solution (Python):
C,D = [int(e) for e in input().split()]

if C <= D:
    m = D
    n = C
else:
    m = C
    n = D

while  n != 0 :
    a = m%n
    m = n
    n = a

J = []

for i in range(1,int(m**0.5)+1):
    if m % i == 0:
        J.append(i)
        if i != m//i:
            J.append(m//i)


J.sort()

N = int(len(J))
M = [1]

for i in range(1,N):
    cnt = 0
    for p in range(1,int(J[i]**0.5)+1):
        if J[i]%p == 0:
            cnt += 1
            if cnt >=2:
                break
    if cnt == 1:
        M.extend([J[i]])


M = int(len(M))

print(M)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import floor, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A, B = MAP()
N = 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

x = factorization(N)
if x == [[1, 1]]:
	print(1)
else:
	print(1+len(x))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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()
    g = gcd(a, b)
    soi = factorization(g)
    
    if soi == [[1, 1]]:
        print(1)
    else:
        print(len(soi) + 1)

if  __name__=='__main__':
    main()

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

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

A, B = [int(x) for x in input().split()]
lst = factorize(gcd(A, B))
print(len(set(lst)) + 1)

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

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

A, B = [int(x) for x in input().split()]
lst = factorize(gcd(A, B))
print(len(set(lst)) + 1)

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

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

A, B = [int(x) for x in input().split()]
lst = factorize(gcd(A, B))
print(len(set(lst)) + 1)

Solution (Python):
C,D = [int(e) for e in input().split()]

if C <= D:
    m = D
    n = C
else:
    m = C
    n = D

while  n != 0 :
    a = m%n
    m = n
    n = a

J = []

for i in range(1,int(m**0.5)+1):
    if m % i == 0:
        J.append(i)
        if i != m//i:
            J.append(m//i)


J.sort()

N = int(len(J))
M = [1]
I = []

for i in range(1,N):
    for p in range(1,int(J[i]**0.5)+1):
        if J[i]%p == 0:
            I.extend([J[i]])
            if int(len(I)) >=2:
                break
    if int(len(I)) == 1:
        M.extend([J[i]])
    I = []


M = int(len(M))

print(M)

Solution (Python):
def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)
 
def prime_factorize(n):
    a = 2
    lst = []
    while a * a <= n:
        if n % a == 0:
            n = n / a
            lst.append(a)
        else:
            a += 1
    if n > 1:
        lst.append(n)
    return lst
 
A, B = map(int, input().split())
n = gcd(A, B)
lst = prime_factorize(n)
print(len(set(lst)) + 1)

Solution (Python):


import fractions

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

def yaku(num):
    temp=[]
    for i in range(2,-int(-num**0.5//1)+1):
        if num%i==0:
            temp.append(i)
            temp.append(num//i)
    temp=list(set(temp))
    if num!=2:
        temp.append(num)
    temp.sort()
    return temp

koyaku=fractions.gcd(A,B)

cand=yaku(min(A,B))


if cand[0]==1:
    print(1)
    exit()

count=0

for i in cand:
    judge=True
    while koyaku%i==0:
        koyaku//=i
        if judge==True:
            count+=1
            judge=False
    if koyaku==1:
        break
print(count+1)

Solution (Python):
import math
from fractions import gcd

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]
    else:
        factor.append(n)
        return factor

n1, n2 = [int(i) for i in input().split()]

n4 = gcd(n1, n2)
n3 = trial_division(n4)

n3.sort()

r1 = 1
c1 = 1
f1 = 1
for i1 in range(len(n3)):
    if c1 != n3[i1]:
        r1 += 1
        c1 = n3[i1]
    if n4 % n3[i1] == 0 and n3[i1] != 1:
        f1 = 0

if f1 == 1 and n4 != 1 :
    r1 += 1

print(r1)

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

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

a_primes = prime_factorize(a).keys()
b_primes = prime_factorize(b)

reply_list = []
for p in a_primes:
    if p in b_primes:
        reply_list.append(p)

print(len(reply_list) + 1)

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

def make_divisors(n):
	divisors = set()
	for i in range(1, int(n**0.5)+1):
		if n % i == 0:
			divisors.add(i)
			if i != n // i:
				divisors.add(n//i)
	return divisors
	
A = make_divisors(a)
B = make_divisors(b)
S = A & B

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
cnt = 1
for i in S:
	if is_prime(i) == True:
		cnt += 1

print(cnt)

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

    return divisors

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

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

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

import fractions
n = fractions.gcd(A, B)
divisors = make_divisors(n)
N = len(divisors)

count = 0
for item in divisors:
    if is_remainder(item):
        count += 1

print(count)

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

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

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

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

import fractions
n = fractions.gcd(A, B)
divisors = make_divisors(n)
N = len(divisors)

count = 0
flag = [0] * N
for item in divisors:
    if is_remainder(item):
        count += 1

print(count)

Solution (Python):
A, B = map(int,input().split())
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0: return a
    r = a % b
    return gcd(b,r)

L = [1]

g = gcd(A, B)
g_copy = gcd(A, B)
i = 2
while g > 1:
    if i > g_copy ** (1/2) :
        if g != 1:
            L.append(i)
        break
    if g % i == 0:
        if L[-1] != i:
            L.append(i)
        g /= i
    else:
        i += 1
print(len(L))

Solution (Python):
import math

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

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

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

    return True

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

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

for a in A_list:
    if a in B_list:
        if is_prime(a):
            cnt += 1

print(cnt)

Solution (Python):
import math 

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

def gdc(A, B):
    if B == 0:
        return A
    else:
        return gdc(B, A % B)

def chk_pn(num):

    flag = True
    if num  <= 3:
        pass

    else:    
        for i in range(2, int(math.sqrt(num)) + 1):
            if num % i == 0:
                flag = False
                break
    return flag


def mk_factor(num):

    max_divisor = int(math.sqrt(num))+1
    divisor = 2
    factor_list = [1]

    while divisor <= max_divisor:
        if num % divisor == 0:
            factor_list.append(divisor)
            num /= divisor
        else:
            divisor += 1
    
    factor_list.append(num)
    return factor_list

GDC = gdc(A, B)
pn_factor = [i for i in mk_factor(GDC) if chk_pn(i) is True]

print(len(set(pn_factor)))

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

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

common_divisor = set(make_divisors(A))&set(make_divisors(B))

ans = 0
for d in common_divisor:
    if is_prime(d):
        ans+=1
    
print(ans+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

div_AandB = list(set(make_divisors(A))&set(make_divisors(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

all_set = set()
for div in div_AandB:
    all_set_next = all_set | set(prime_factorize(div))
    all_set = all_set_next
print(len(list(all_set))+1)

Solution (Python):
from math import sqrt
A, B = map(int, input().split())
def func(N):
    S = set()
    for i in range(1, int(sqrt(N))):
        if N % i == 0:
            S.add(i)
            S.add(N//i)
    if N % int(sqrt(N)) == 0:
        S.add(int(sqrt(N)))
    return S

def one_and_prime_check(N):
    for i in range(2, int(sqrt(N))+1):
        if N % i == 0:
            return False
    return True

D = list(func(A) & func(B))
ans = 0
for d in D:
    if one_and_prime_check(d):
        ans += 1
print(ans)

Solution (Python):
from math import sqrt
A, B = map(int, input().split())
def func(N):
    S = set()
    for i in range(1, int(sqrt(N))):
        if N % i == 0:
            S.add(i)
            S.add(N//i)
    if N % int(sqrt(N)) == 0:
        S.add(int(sqrt(N)))
    return S

D = sorted(list(func(A) & func(B)))
N = len(D)
check = [0]*N
for i in range(N):
    if i == 0 or check[i] == 1:
        continue
    for j in range(i+1, N):
        if D[j] % D[i] == 0:
            check[j] = 1

ans = check.count(0)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)

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

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

A, B = map(int, input().split())
x = gcd(A, B)
prime_list = prime_decomposition(x)
s = set(prime_list)
print(len(s)+1)

Solution (Python):


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



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

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

if A > B:
    g = GCD(A, B)
else:
    g = GCD(B, A)

l  = factorize(g)

print(len(set(l)) + 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
import fractions
gcd = math.gcd if hasattr(math, "gcd") else fractions.gcd

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

print(len(set(factorize(g)))+1)

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

from fractions import gcd

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

Solution (Python):
def f(n):
    result = set()
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            result.add(i)

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

    return result

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

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

print(len(fa & fb)+1)

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

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

count = 1
for i in range(2, ceil(sqrt(gcd_)) + 1):
    if gcd_ % i == 0:
        count += 1
        while gcd_ % i == 0:
            gcd_ /= i

if gcd_ != 1:
    count += 1

print(count)

Solution (Python):
import math

def is_prime(n):
	if n < 2: return False

	for i in range(2, math.ceil(math.sqrt(n))):
		if n % i == 0:
			return False

	return True

def get_pf(n):
	ans = [1]

	for p in range(2, math.ceil(math.sqrt(n))):
		while n % p == 0:
			n = int(n / p)
			ans.append(p)

	if n != 1:
		ans.append(n)

	return ans

if __name__ == "__main__":
	line = input().split(" ")

	a, b = int(line[0]), int(line[1])

	if a > b:
		a, b = b, a

	primes_a = set(get_pf(a))
	primes_b = set(get_pf(b))

	
	
	

	ans = []
	for e in primes_a:
		if e in primes_b:
			ans.append(e)

	
	print(len(ans))

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

def gcd(i,j):
  if i > j:
    i,j = j,i
  j %= i
  if j == 0:
    return i
  else:
    return gcd(j,i)

g = 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
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)
    cnt = factorization(c)
    if cnt[0][0]==1:
        print(len(cnt))
    else:
        print(len(cnt)+1)

if __name__ == "__main__":
    main()

Solution (Python):
import math

a, b = map(int, input().split())
fa = []
fb = []

tmp = int(math.sqrt(a)) + 1
for i in range(2,tmp):
    while a % i == 0:
        a //= i
        fa.append(i)
if a != 1:
    fa.append(a)

tmp = int(math.sqrt(b)) + 1
for i in range(2,tmp):
    while b % i == 0:
        b //= i
        fb.append(i)
if b != 1:
    fb.append(b)

print(len(list(set(fa) & set(fb))) + 1)

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

def prime_factorize(N):
    prime_set=set([1])
    while N%2==0:
        prime_set.add(2)
        N//=2
    
    f=3
    while f*f<=N:
        if N%f==0:
            prime_set.add(f)
            N//=f
        else:
            f+=2
        
    if N!=1:
        prime_set.add(N)

    return prime_set

A=prime_factorize(a)
B=prime_factorize(b)

print(len(A.intersection(B)))

Solution (Python):
from fractions import gcd
A, B = map(int,input().split())
C = gcd(A,B)
C0 = C
 
p = {}
for i in range(2,10**6):
    if C % i == 0:
        p[i] = 0
        while C % i == 0:
            C //= i
            p[i] += 1
    if i * i > C0:
        break
if C != 1:
  p[C] = 1
 
print(len(p) + 1)

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

a,b=map(int,input().split())
g=gcd(a,b)
m=g
c=1
i=2
while i*i<=g:
    if m%i==0:
        c+=1
    while m%i==0:
        m=m//i
    i+=1
if m>1:
    c+=1
print(c)

Solution (Python):
N,M = map(int, input().split())

NL=[]
ML=[]
for i in range(1, int(N**0.5)+1):
    if N%i==0:
        NL.append(i)
        if i != N//i:
            NL.append(N//i)
for i in range(1, int(M**0.5)+1):
    if M%i==0:
        ML.append(i)
        if i != M//i:
            ML.append(M//i)
NL.remove(1)
NL.sort()
L=[]
for i in NL:
    if i in ML:
        for j in L:
            if i%j==0:
                break
        else:
            L.append(i)
print(len(L)+1)

Solution (Python):
import math

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

def gcd(x, y):
  z = x % y
  if z == 0:
    return y
  else:
    return gcd(y, z)
  
def common_divisors(x, y):
  xd = make_divisors(x)
  xd.append(1)
  xd.append(x)
  yd = make_divisors(y)
  yd.append(1)
  yd.append(y)
  return set(xd).intersection(yd)

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

divisors = common_divisors(a, b)
divisors_set = frozenset(divisors)

res = []

for n in divisors:
  if n == 1 or n == 2 or n == 3:
    res.append(n)
  elif n % 2 == 0:
    continue
  else:
    dvs = set(make_divisors(n))
    if len(dvs) == 0 or not dvs <= divisors_set:
      res.append(n)

print("{}".format(len(res)))

Solution (Python):
from fractions import gcd

a, b = map(int, input().split())
g = gcd(a, b)
m = gcd(a, b)

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

if m > 1:
    c += 1
print(c)

Solution (Python):


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


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

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



print(len(factorize(G)) + 1)

Solution (Python):
import math
import fractions
gcd = math.gcd if hasattr(math, "gcd") else fractions.gcd

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

print(len(set(factorize(g)))+1)