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:
import math
from fractions import gcd
a, b = map(int, input().split())
g = gcd(a, b)
sqrt = math.floor(g ** 0.5)
factors = [1]
z = g
for i in range(2, sqrt + 1):
    if not z % i:
        factors.append(i)
        while z % i == 0:
            z //= i
if z > 1:
    factors.append(z)
print(len(factors))

Submission status: Accepted

Solution code:
from fractions import gcd

# gcd(A,B)の素因数分解したときの素数の数+1が最大
# なぜならば任意の公約数C|A,C|BはC|gcd(A,B)
# Cとして素因数+1より大きいの数を選ぶと、Cはどこかの素数で重複して互いに素にならない

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

ret = 1
prime_len = 10**6+1
prime_factor = [False]*prime_len
for p in range(2, prime_len):
    while D%p == 0:
        if prime_factor[p] == False:
            ret += 1
            prime_factor[p] = True
            
        D = D//p
        
    if D == 1: break

# 10^6以下の素因数を探索して、1でなければ10^12以下の数は素数である。（10^6<p,p^\primeならば10^12 < p \cdot p^\prime）
if D != 1: ret += 1
    
print(ret)

Submission status: Accepted

Solution code:
from fractions import gcd

def factorization(n):
    res = []
    m = 2
    while m ** 2 <= n:
        if n % m == 0:
            cnt = 0
            while n % m == 0:
                cnt += 1
                n //= m
            res.append([m, cnt])
        m += 1

    if n > 1:
        res.append([n, 1])

    return res


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

Submission status: Accepted

Solution code:
import math
import sys
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 euclid(a, b):
  if b == 0:
    return a
  else:
    return euclid(b, a%b)
a,b=map(int,input().split())
c=euclid(a,b)
if c==1:
  print(1)
  sys.exit()
print(len(factorization(c))+1)

Submission status: Accepted

Solution code:
from math import ceil
from fractions import gcd

a, b = map(int, input().split())
c = gcd(a, b)
count = 1
for num in range(2, ceil(c**0.5) + 1):
  if c % num == 0:
    count += 1
    while c % num == 0:
      c = c // num
if c > 1:
  count += 1
print(count)

Submission status: Accepted

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

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


"""
最大公約数を素因数分解すればいけそう？
"""

target = gcd(a,b)
pftarg = pfact(target).items()
print(len(pftarg)+1)

Submission status: Accepted

Solution code:
import fractions
a,b=map(int,input().split())

g=fractions.gcd(a,b)
org=g
counter=1
for i in range(2,int(g**0.5)+1):
	if g%i == 0:
		counter += 1
		g //= i
		while g % i ==0:
			g //= i

if g > int(org ** 0.5):
	counter += 1

print(counter)

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
import fractions
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    a,b = map(int,ipt().split())
    g = fractions.gcd(a,b)

    #素因数分解
    def factorization(n):
        d = dict()
        ni = n
        pn = 2
        t = 0
        while pn**2 <= n and ni > 1:
            if ni%pn == 0:
                t += 1
                ni //= pn
            else:
                if not t == 0:
                    d[pn] = t
                    t = 0
                if pn == 2:
                    pn = 3
                else:
                    pn += 2
        if t > 0:
            d[pn] = t
        if ni > 1:
            d[ni] = 1
        return d

    d = factorization(g)
    print(len(d.keys())+1)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

a,b=list(map(int,input().split()))
min_num=min(a,b)
gcd=[]

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

for i in range(1,int(math.sqrt(min_num)+1)):
  if a%i==0:
    if b%i==0:
      gcd.append(i)
    if b%(a//i)==0:
      gcd.append(a//i)

prime_list=[]
for i in gcd:
  if prime(i):
    prime_list.append(i)
if a==1 or b==1:
  print(len(prime_list)-1)
else:
  print(len(prime_list))

Submission status: Accepted

Solution code:
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[i] = cnt

    if temp!=1:
        arr[temp] = 1

    if arr=={}:
        arr[n] = 1

    return arr


a, b = map(int, input().split()) 
a_fac = factorization(a)
b_fac = factorization(b)
lcm = {}
for prime,cnt in a_fac.items():
    if prime in b_fac and prime != 1:
        lcm[prime] = min(cnt, b_fac[prime])

print(len(lcm)+1)

Submission status: Accepted

Solution code:

from collections import Counter
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())
p1 = Counter(prime_decomposition(A))
p2 = Counter(prime_decomposition(B))
ans = 1
for p,_ in p1.items():
  if p2[p] > 0:
    ans += 1

print(ans)

Submission status: Accepted

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


def pf(v):
    result = 1
    for i in range(2, v + 1):
        if v < i * i:
            if v > 1:
                result += 1
            break
        if v % i == 0:
            result += 1
        while v > 1 and v % i == 0:
            v //= i
    return result


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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=1
for i in range(2,int(max(a**.5,b**.5))+2):
    if a%i==0==b%i:
        c+=1
    while a%i==0:
        a//=i
    while b%i==0:
        b//=i
if a==b!=1:
    c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b)

a, b = [int(i) for i in input().split()]
ma = gcd(a, b)
st = set()
for i in range(1, int(math.sqrt(ma) + 1)):
	if ma % i == 0:
		flg = True
		for j in st:
			if gcd(i, j) != 1:
				if i < j:
					st.remove(j)
					st.add(i)
				flg = False
				break
		if flg:
			st.add(i)
		flg = True
		ii = ma // i
		for j in st:
			if gcd(ii, j) != 1:
				if ii < j:
					st.remove(j)
					st.add(ii)
				flg = False
				break
		if flg:
			st.add(ii)
print (len(st))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# 1. 素因数分解して公約数を作成(A,B共に)
# 2. 

from collections import Counter # N : 素因数分解


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


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

prime_A = calc_prime_factor(A)
prime_B = calc_prime_factor(B)

print(len(list(set(Counter(prime_A).keys()) & set(Counter(prime_B).keys()))) + 1)

Submission status: Accepted

Solution code:
a, b = list(map(int, input().split(' ')))
def gcd(l, s):
  return l if s == 0 else gcd(s, l % s)

temp = gcd(a, b)

ans = 0
for i in range(2,1000000):
  if temp % i == 0:
    ans += 1
    while temp % i == 0:
      temp = temp // i
  if temp == 1:
    break
if temp != 1:
  ans += 1

print(ans+1)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
while a > 0:
    a, b = b % a, a
ret = 1
d = 2
while b >= d * d:
    if b % d == 0:
        ret += 1
        while b % d == 0:
            b //= d
    d += 1
if b > 1:
    ret += 1
print(ret)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun  3 14:11:35 2020

@author: NEC-PCuser
"""
def gcd(a, b):
    
    if (a % b == 0):
        return b
    return gcd(b, a % b)

def factorize(num):
    i = 2
    factorize_list = []
    num_tmp = num
    while i * i <= num_tmp:
        count = 0
        if num % i == 0:
            while num % i == 0:
                count += 1
                num //= i
            factorize_list.append([i, count])
        i += 1
    if num != 1:
        factorize_list.append([num, 1])
    return factorize_list 
                


if __name__ == "__main__":
    A, B =  map(int, input().split())
    big_num = max(A, B)
    short_num = min(A, B)
    gcd_num = gcd(big_num, short_num)
    print(len(factorize(gcd_num)) + 1)

Submission status: Accepted

Solution code:
def pfact(n):
    d = {}
    while n % 2 == 0:
        d[2] = 1 if 2 not in d else d[2] + 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            d[f] = 1 if f not in d else d[f] + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = 1 if n not in d else d[n] + 1
    return d

a, b = map(int, input().split())
A = pfact(a)
B = pfact(b)
d = {}
ans = 1
for k in A.keys():
    if k in B:
        ans += 1
print(ans)

Submission status: Accepted

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

def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return int(a*b/gcd(a,b))

g=gcd(a,b)
def prime_factorization(n):
    #nを素因数分解して、昇順のリストを返す
    m=n
    ans = []
    p = 2

    while p<m**0.5:
        if n%p == 0:
            ans.append(p)
            while n%p==0:
                n /= p
        else:
            p += 1
            
    if n!=1:
        ans.append(int(n))
    
    return ans

l=prime_factorization(g)
print(len(l)+1)

Submission status: Accepted

Solution code:
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())
C, D = prime_factorize(A), prime_factorize(B)
C.append(1)
D.append(1)
C = set(C)
D = set(D)
print(len(C & D))

Submission status: Accepted

Solution code:
from fractions import gcd


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


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

print(len(prime_factorize(gcd(A, B))) + 1)

Submission status: Accepted

Solution code:
from fractions import gcd


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


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

li = make_prime_factors2(gcd(a, b))
print(len(li) + 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

a,b = map(int,input().split())
c = gcd(a,b)
d = factorization(c)
print(len(d)+1-(c==1))

Submission status: Accepted

Solution code:
import math
a, b = map(int, input().split())

def is_prime(num):
    if num == 2:
        return True
    elif num <  3 or num % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(num)) + 1, 2):
        if num % i == 0:
            return False
    return True

if b > a:
    a, b = b, a
c = []
for i in range(1, int(math.sqrt(b))+1):
    if b%i == 0:
        k = b//i
        if a%k == 0:
            if is_prime(k):
                c.append(k)
        if a%i == 0:
            if is_prime(i):
                c.append(i)
print(len(set(c))+1)

Submission status: Accepted

Solution code:
import math
a, b = map(int, input().split())

def is_prime(num):
    if num == 2:
        return True
    elif num <  3 or num % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(num)) + 1, 2):
        if num % i == 0:
            return False
    return True

if b > a:
    a, b = b, a
c = []
for i in range(1, int(math.sqrt(b))+1):
    if a%i == 0 and b%i == 0:
        if is_prime(i):
            c.append(i)
    k = b//i
    if a%k == 0:
        if is_prime(k):
            c.append(k)
print(len(set(c))+1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush
from fractions import gcd

def solve():
    a, b = MI()

    g = gcd(a, b)

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

    fact = prime_factorization(g)
    print(len(fact) + 1)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from fractions import gcd

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

gcd=gcd(a,b)
ab_gcd=gcd

f=[]
for i in range(2,int(ab_gcd**0.5)+1):
    while gcd%i==0:
        gcd=gcd//i
        f.append(i)
if gcd!=1:
    f.append(gcd)

print(len(set(f))+1)

Submission status: Accepted

Solution code:
import sys
import math
input = lambda: sys.stdin.readline().rstrip()


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


def solve():
    A, B = map(int, input().split())
    ap = factorize(A)
    bp = factorize(B)
    ans = 1 + len(ap & bp)
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

print(len(prime_factor(g))+1)

Submission status: Accepted

Solution code:
def f(a,b):
    if b:return f(b,a%b)
    p=set()
    for i in range(2,int(a**0.5)+1):
        while True:
            if a%i==0:
                a//=i
                p.add(i)
            else:
                break
    if a!=1:
        return len(p)+2
    return len(p)+1
print(f(*map(int,input().split())))

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


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


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 main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())

    g = gcd(a, b)

    ans = 0

    for i in range(1, int(g ** 0.5) + 1):
        if g % i == 0:
            if is_prime(i) or i == 1:
                ans += 1
            if is_prime(g // i) and i != g // i:
                ans += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
import fractions

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

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

l = sorted(list(set(make_divisors(A)) & set(make_divisors(B))))
#print(l)
i = 0
while i < len(l):
    v = l[i]
    if v == 1:
        i += 1
        continue
    l = l[0:i+1] + list(filter(lambda x: x % v != 0, l[i+1:]))
#    print(l)
    i += 1
print(len(l))

Submission status: Accepted

Solution code:
import fractions

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

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

l = sorted(list(set(make_divisors(A)) & set(make_divisors(B))))
#print(l)
i = 0
while i < len(l):
    v = l[i]
    if v == 1:
        i += 1
        continue
    l = l[0:i+1] + list(filter(lambda x: x % v != 0, l[i+1:]))
#    print(l)
    i += 1
print(len(l))

Submission status: Accepted

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

pa = factorization(a)
pb = factorization(b)

print(len(({1} | {x for x, y in pa}) & ({1} | {x for x, y in pb})))

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
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  
a,b = map(int,input().split())
a_list = make_divisors(a)
b_list = make_divisors(b)
a_b_and = set(a_list) & set(b_list)
a_b_and = list(a_b_and)


count = 1
for a_b in a_b_and:
  if is_prime(a_b) == True:
    count += 1
    
print(count)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a<b:
        a,b = b,a
    r = a%b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b

a,b = list(map(int,input().split()))
c = gcd(a,b)
c0 = c
r = 2
lis = [1]
count = 1
while c != 1:
    if c%r == 0:
        c = c//r
        lis.append(r)
        r = 2
    else:
        r += 1
    if r > int(pow(c0,0.5))+1:
        lis.append(c)
        break
d = list(set(lis))
print(len(d))

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

s = set([i for i,k in factorization(a)])
t = set([i for i,k in factorization(b)])
if a==1 and b==1:
  print(1)
else:
  print(len(s&t)+1)

Submission status: Accepted

Solution code:
import fractions

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

g = fractions.gcd(A, B)

def prime_decompose(x):
    decomposed = []
    for i in range(2,int(pow(x,0.5))+1):
        while x % i == 0:
            x //= i
            decomposed.append(i)
    if x > 1:
        decomposed.append(x)
    return decomposed

g_dec = set(prime_decompose(g))
print(len(g_dec)+1)

Submission status: Accepted

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

def prime_decompose(x):
    decomposed = []
    for i in range(2,int(pow(x,0.5))+1):
        while x % i == 0:
            x //= i
            decomposed.append(i)
    if x > 1:
        decomposed.append(x)
    return decomposed

A_dec = set(prime_decompose(A))
B_dec = set(prime_decompose(B))

ans = 1
for a in A_dec:
    if a in B_dec:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
a,b = [int(x) for x in input().split()]
import fractions
g = fractions.gcd(a,b)
ans = 1
mama = int(g ** (1/2))
flag = 0
for i in range(2,mama+2):
    while True:
        if g%i != 0:
            break
        else:
            g = g/i
            flag = 1
    if flag == 1:
        ans += 1
    flag = 0
if g != 1:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
a,b=n1()
# from math import gcd
from fractions import gcd
m=gcd(a,b)

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

gcd_list=make_divisors(m)
if len(gcd_list)==1:
    print(1)
else:
    prime=[]
    for i in gcd_list[1:]:
        for j in prime:
            if i%j==0:
                break
        else:
            prime.append(i)
    print(len(prime)+1)

Submission status: Accepted

Solution code:
from fractions import gcd
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
print(len(set(prime_factorize(gcd(a, b)))) + 1)

Submission status: Accepted

Solution code:
from fractions import gcd
from math import sqrt

a,b = map(int,input().split())
n = gcd(a,b)
k = n
s = set()
s.add(1)
for i in range(2,int(sqrt(n))+1):
  while n%i == 0:
    n = n//i
    s.add(i)
  if n == 1:
    break
s.add(n)
print(len(s))

Submission status: Accepted

Solution code:
def p(n):
    i = 2
    t = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            t.append(i)
        i += 1
    if n > 1:
        t.append(n)
    return t


def main():
    from fractions import gcd
    a, b = map(int, input().split())
    g = gcd(a, b)
    print(len(set(p(g))) + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def c(n):
    b = 2
    f = set()
    while b * b <= n:
        while n % b == 0:
            n //= b
            f |= {b}
        b += 1
    if n > 1:
        f |= {n}
    return f
a, b = map(int, input().split())
print(len(c(a) & c(b)) + 1)

Submission status: Accepted

Solution code:
# import math
from fractions import gcd

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

#最大公約数: greatest common divisor(gcd)
# g = math.gcd(a,b)
g=gcd(a,b)

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

Submission status: Accepted

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

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

if gcd(A,B)==1:
  temp = 0
else:
  temp = 1

print(len(factorization(gcd(A,B)))+temp)

Submission status: Accepted

Solution code:
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

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

    def bunkai(num):
        p = set()
        p.add(1)
        i = 2
        while i * i <= num:
            while num%i == 0:
                p.add(i)
                num //= i
            i += 1
        p.add(num)
        return p

    a = bunkai(A)
    b = bunkai(B)
    print(len(a & b))

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
import sys
a,b = map(int,input().split())
g = gcd(a,b)
ans = 1
if g % 2 == 0:
    ans += 1
    while g % 2 == 0:
        g //= 2
if g == 1:
    print(ans)
    sys.exit()
for i in range(3,int(g**(0.5))+2,2):
    if g % i == 0:
        ans += 1
        while g%i == 0:
            g //= i
    if g == 1:
        break
else:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
import math
import fractions

g = fractions.gcd(a, b)
gs = [1]

f = 2
if g % 2 == 0:
  gs.append(2)
while g % 2 == 0:
  g = g // 2
f = 3
while f * f <= g:
  if g % f == 0:
    gs.append(f)
  while g % f == 0:
    g = g // f
  f += 2
if g != 1:
  gs.append(g)
print(len(gs))

Submission status: Accepted

Solution code:
import math
A,B = map(int,input().split())
Anum=[]
Bnum=[]

for i in range(2,int(math.sqrt(A)+1)):
    while A % i ==0:
        A //= i
        if i not in Anum:
            Anum.append(i)
if A!=1:
    Anum.append(A)


for i in range(2,int(math.sqrt(B)+1)):
    while B % i ==0:
        B //= i
        if i not in Bnum:
            Bnum.append(i)
if B!=1:
    Bnum.append(B)

ABnum=set(Anum) & set(Bnum)
print(len(ABnum)+1)

Submission status: Accepted

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

print(len(set(prime_factorize(a))&set(prime_factorize(b)))+1)

Submission status: Accepted

Solution code:
from fractions import gcd

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

c = set(prime_factorize(g))
print(len(c)+1)

Submission status: Accepted

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

#from math import gcd
from fractions import gcd

g = gcd(a,b)

pf = {}

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

ans = 1 + len(pf.keys()) # 1は素数ではないが答えには入る

print(ans)

Submission status: Accepted

Solution code:
def factorization(n,m):
    temp = n
    temp2 = m
    cnt=1
    for i in range(2, int(-(-min(n,m)**0.5//1))+1):
        if temp%i==0:
            if temp2%i == 0:
                cnt += 1
                while temp2%i==0:
                    temp2 //= i
            while temp%i==0:
                temp //= i
        elif temp2%i == 0:
            while temp2%i==0:
                temp2 //= i

    if temp != 1 and temp2 != 1:
        if max(temp, temp2) % min(temp, temp2) == 0: cnt += 1

    return cnt

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

Submission status: Accepted

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

from itertools import combinations

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

gcd_n = gcd(a,b)

#L = [i for i in range(1,gcd_n+1) if gcd_n%i==0]

def div(num):
    l = [1]
    if(num==1):
        return [1]
    while(num%2==0):
        num //=2
        l.append(2)
    f = 3
    while(f*f<=num):
        if num%f==0:
            num //= f
            l.append(f)
        else:
            f += 2
    
    if num!=1:
        l.append(num)
    return l

l = div(gcd_n)
cnt = 0
pre = 0
for i in range(len(l)):
    if pre==l[i]:
        continue
    pre = l[i]
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from fractions import gcd
from math import factorial


def nCr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)


def lcm(x, y):
    return (x * y) // gcd(x, y)


def prime_numbers(n):
    if n < 2:
        return [1]
    primes = []
    for p in range(2, int(pow(n, 0.5)) + 1):
        if p * p > n:
            break
        while n % p == 0:
            primes.append(p)
            n //= p
    if n > 1:
        primes.append(n)
    return primes


def m():
    a, b = map(int, input().split())
    x = gcd(a, b)
    p = prime_numbers(x)
    p.append(1)

    return len((set(p)))


print(m())