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.



Sample input:
12 18


Sample output:
3

Submission status: Accepted

Solution code:
def trial_division(n,b):
    a = []
    if n%2==0 and b%2==0:
        a.append(2)
    while n % 2 == 0:
        n /= 2
    f = 3
    while f*f <= n:
        if n % f == 0: 
            if b%f == 0:
                a.append(f)
            n /= f
        else:
            f += 2   
    if n != 1 and b%n==0: 
        a.append(n)
    return a
A,B = (lambda x: (min(x),max(x)))(list(map(int,input().split())))
print(len(set(trial_division(A,B)))+1)

Submission status: Accepted

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

A = collections.Counter(prime_factorize(A)).keys()
B = collections.Counter(prime_factorize(B)).keys()


cms = []
for a in A:
    for b in B:
        if(a==b):
            cms.append(a)
print(len(cms)+1)

Submission status: Accepted

Solution code:
from enum import Enum
from queue import Queue

import numpy as np

import collections
import bisect
import sys
import math

from scipy.sparse.csgraph import floyd_warshall

"""nを素因数分解"""
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
 #最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a


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

G = gcd(A,B)

c = collections.Counter(factorize(G))
print(len(list(c.keys()))+1)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
from collections import defaultdict

def comdiv(n):
  end = int(n**0.5) + 2
  dic = defaultdict(lambda: 0)
  for i in range(2, end):
    while n % i == 0:
      n //= i
      dic[i] += 1
  else:
    if n > 1:
      dic[n] = 1
  return dic

A = comdiv(a).keys()
B = comdiv(b).keys()
C = set(A) & set(B)
print(len(C) + 1)

Submission status: Accepted

Solution code:
def prime_factorize(n):
    a=[]
    while n%2==0:
        a.append(2)
        n //=2
    f=3
    while f**2<=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())
print(len(set(prime_factorize(a))&set(prime_factorize(b)))+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from math import gcd
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

# 2つの入力を空白で分割し、数値化
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))

Submission status: Accepted

Solution code:
"""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())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

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

Submission status: Accepted

Solution code:
# D - Disjoint Set of Common Divisors
A, B = map(int, input().split())

from fractions import gcd

# nの素数判定
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

# nの約数列挙
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 #sortされていない

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

print(ans+1)

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#16:44
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)

Submission status: Accepted

Solution code:
"""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])
# print(lst1)
# print(lst2)

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

result_set = lst1_set & lst2_set


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

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)
    #print(soi)
    if soi == [[1, 1]]:
        print(1)
    else:
        print(len(soi) + 1)

if  __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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))
#print(cand)

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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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
#Sから素数だけを抽出してカウント
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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(pn_factor)
print(len(set(pn_factor)))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# ABC142 D - Disjoint Set of Common Divisors

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


#Trial Division
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

	# if b % a == 0 and is_prime(a):
	# 	primes_a.add(a)
	# 	primes_b.add(a)

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

	# print(ans)
	print(len(ans))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)))