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:
# ABC142D - Disjoint Set of Common Divisors
from fractions import gcd
# from math import gcd


def divisors(n: int) -> set:
    div = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            div.add(i), div.add(n // i)
    return sorted(div)


def main():
    A, B = map(int, input().split())
    divs = divisors(gcd(A, B))
    divs.pop(0)  # 1 divides all numbers -> pop
    groups = set()
    for i in divs:
        if all(i % x for x in groups):
            groups.add(i)  # coprime to all numbers in "groups"
    ans = len(groups) + 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

prime_A = set()
prime_B = set()

curr = 2
while A > 1:
  if A%curr == 0:
    prime_A.add(curr)
    A = A//curr
  elif curr*curr >=A:
    prime_A.add(A)
    A = 1
  else:
    curr+=1
    
curr = 2
while B > 1:
  if B%curr == 0:
    prime_B.add(curr)
    B = B//curr
  elif curr*curr >=B:
    prime_B.add(B)
    B /= B
  else:
    curr+=1
print(len(prime_A& prime_B)+1)

Submission status: Accepted

Solution code:
# ABC142D - Disjoint Set of Common Divisors
def divisors(n: int) -> set:
    div = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            div.add(i), div.add(n // i)
    return div


def main():
    A, B = map(int, input().split())
    divs = sorted(divisors(A) & divisors(B))
    divs.pop(0)
    groups = set()
    for i in divs:
        if all(i % x for x in groups):
            groups.add(i)
    ans = len(groups) + 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import sqrt, ceil
 
a, b = map(int, input().split())
 
c_a = set()
c_b = set()
 
for i in range(1, ceil(sqrt(a))+1):
  if a % i == 0:
    c_a.add(i)
    if i > 1:
        while a % i == 0:
            a = a // i
if a != 1:
    c_a.add(a)
 
for j in range(1, ceil(sqrt(b))+1):
  if b % j == 0:
    c_b.add(j)
    if j > 1:
        while b % j == 0:
            b = b // j
if b != 1:
    c_b.add(b)
 
ans = c_a.intersection(c_b)
 
print(len(ans))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
def factor(n):
    a = []
    while not n%2:
       n//=2
       a.append(2)
    i = 3
    while i*i<=n:
        while not n%i:
            n//=i
            a.append(i)
        i+=2
    if n>1:
        a.append(n)
    return a
print(len(set(factor(a))&set(factor(b)))+1)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import sys
from fractions import gcd
from collections import Counter

def prime_factorization(n):
    """nを素因数分解する
    return d(dict): 素因数をキー、素因数の指数部を値とするディクショナリを返す

    n=140: d = {2: 2, 5: 1, 7: 1}
    """
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m = m + 1 if m == 2 else m + 2

    if n > 1:
        d[n] += 1
    return d


def solve():
    A, B = list(map(int, sys.stdin.readline().split()))
    cd = gcd(A, B)

    if cd == 1:
        print(1)
        return

    """
    (素因数分解の素因数の個数)+1が答え
    """

    prime_d = prime_factorization(cd)
    print(len(prime_d)+1)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

print(len(set(factorize(gcd(a,b))))+1)

Submission status: Accepted

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

def factorize(n):
    pnum = []
    for i in range(2,int(n**0.5)+1):
        if n%i != 0:
            continue
        pnum.append([i,0])
        while n%i == 0:
            n /= i
            pnum[-1][1] += 1
    if n != 1:
        pnum.append([int(n),1])
    return pnum
    
a,b = map(int,input().split())
n = gcd(a,b)
pnum = factorize(n)
print(len(pnum)+1)

Submission status: Accepted

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

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

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

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

    return arr

fac = factorization(g)
fac

if fac[0][0] == 1:
    ans = 1
else:
    ans = len(fac)+1
print(ans)

Submission status: Accepted

Solution code:
from subprocess import*
a,b=[set(Popen(('factor',x),stdout=PIPE).stdout.read().split()[1:])for x in input().split()]
print(len(a&b)+1)

Submission status: Accepted

Solution code:
import fractions
A, B = map(int, input().split())
GCD = fractions.gcd(A, B)
k = 1
cnt = 1
while GCD > 1:
  k += 1
  if k ** 2 > GCD:
    cnt += 1
    break
  if GCD % k:
    continue
  cnt += 1
  while GCD % k == 0:
    GCD //= k
print(cnt)

Submission status: Accepted

Solution code:
from subprocess import*;a,b=[set(Popen(('factor',x),stdout=PIPE).stdout.read().split()[1:])for x in input().split()];print(len(a&b)+1)

Submission status: Accepted

Solution code:
#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されていない

#nの素因数分解(O(n**0.5)
def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.append(i)
            n = n//i
    if n != 1:
        ass.append(n)
    return ass


if __name__ == '__main__':
    ta, tb = map(int,input().split())

    # めんどくさいのでa<=bの場合で考える
    if ta > tb:
        a = tb
        b = ta
    else:
        a = ta
        b = tb

    a_div_set = set(divisor(a))
    b_div_set = set(divisor(b))
    common_div_set = (a_div_set & b_div_set)

    answer = 0
    for e in common_div_set:
        if e == 1 or is_prime(e):
            answer += 1
    print(answer)

Submission status: Accepted

Solution code:
import fractions
import sys

input = sys.stdin.readline


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


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

    # 素因数分解
    g = fractions.gcd(a, b)
    print(len(set(factorization(g))) + 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import fractions as f,subprocess as s;print(len(set(s.Popen(('factor',str(f.gcd(*map(int,input().split())))),stdout=s.PIPE).stdout.read().split())))

Submission status: Accepted

Solution code:
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x
  
def pf(x):
    s = []
    while x % 2 == 0:
        s.append(2)
        x = x // 2
    i = 3
    while i**2 <= x:
        while x % i == 0:
            s.append(i)
            x = x // i
        i = i + 2
    if x != 1:
        s.append(x)
    return(s)
A, B = list(map(int,input().split()))
x = gcd(A, B)
ans = pf(x)
ans = set(ans)
print(len(ans)+1)

Submission status: Accepted

Solution code:
import math

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

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

def prime_factorize(n):
    res = []
    tmp = n

    for i in range(2, int(math.sqrt(n))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            res.append([i, cnt])

    if tmp != 1:
        res.append([tmp, 1])

    if len(res) == 0 and n != 1:
        res.append([n, 1])

    return(res)

# AとBの公約数は
# AとBの最大公約数の約数に等しい
# ここではAとBの2個なのでAとBの約数を列挙して
# setの&などで共通部分を取っても良いが
# もっと個数が多い時はこの方法でやらないと遅いので使える方法だよ
g = gcd(A, B)
div = prime_factorize(g)
ans = len(div) + 1
print(ans)

Submission status: Accepted

Solution code:
import fractions as f,subprocess as s;print(len(set(s.Popen(('factor',str(f.gcd(*map(int,input().split())))),stdout=s.PIPE).communicate()[0].split())))

Submission status: Accepted

Solution code:
import fractions as f,subprocess as s;print(len(set(s.Popen(('factor',str(f.gcd(*map(int,input().split())))),stdout=s.PIPE).communicate()[0].split()[1:]))+1)

Submission status: Accepted

Solution code:
import fractions as f,subprocess as s;print(len(set(map(int,s.Popen(('factor',str(f.gcd(*map(int,input().split())))),stdout=s.PIPE).communicate()[0].split()[1:])))+1)

Submission status: Accepted

Solution code:
from fractions import*
from subprocess import*
print(len(set(map(int,Popen(('factor',str(gcd(*map(int,input().split())))),stdout=PIPE).communicate()[0].split()[1:])))+1)

Submission status: Accepted

Solution code:

from fractions import gcd
import itertools
import sys
input = sys.stdin.readline


# 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)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass


# 素因数分解
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 coprime(a, b):
    return gcd(a, b) == 1


def main():
    A, B = map(int, input().split())
    gcdab = gcd(A, B)
    cd = divisor(gcdab)
    # print(factorization(gcdab))
    # print(cd)
    # da = sorted(divisor(A))
    # db = sorted(divisor(B))
    # cd = []
    # for i in da:
    #     if i in db:
    #         cd.append(i)

    ans = 0

    for i in cd:
        if is_prime(i) or i == 1:
            ans += 1

    print(ans)

    # print(cd)
    # li = []
    # # c = itertools.combinations(cd, 2)
    # for i in cd:
    #     if i == 1:
    #         li.append(i)
    #         continue

    #     flg = True
    #     for c in li:
    #         if not coprime(i, c):
    #             flg = False

    #     if flg:
    #         li.append(i)

    # # print(li)
    # print(len(li))


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def factorize(n):
    res = set()

    diviser = 2
    exponent = 0
    while n % diviser == 0:
        exponent += 1
        n //= diviser
    if exponent > 0:
        res.add((diviser, exponent))
    # 2の冪数を先に調べることで、
    # diviserを奇数に限定できる

    to = int(pow(n, 0.5))
    for diviser in range(3, to + 1, 2):
        exponent = 0
        while n % diviser == 0:
            exponent += 1
            n //= diviser
        if exponent > 0:
            res.add((diviser, exponent))

    if n > 1:
        res.add((n, 1))
        # n:素数の場合

    return res


def main():
    a, b = map(int, input().split())
    g = gcd(a, b)
    e = factorize(g)

    ans = len(e) + 1
    # factorizeで、素数の種類数が分かる
    # 1で割る分を +1 で加算する
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

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

def prime_factorize(n):
    res = []
    tmp = n

    for i in range(2, int(math.sqrt(n))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            res.append([i, cnt])

    if tmp != 1:
        res.append([tmp, 1])

    if len(res) == 0 and n != 1:
        res.append([n, 1])

    return(res)

c = gcd(A, B)
#print(c)
div = prime_factorize(c)
#print(div)
ans = len(div) + 1
print(ans)

Submission status: Accepted

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

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

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

print(len(factorize(gcd(a,b)))+1)


"""        
cf = []
for i in range(2,min(a,b)+1):
    if a % i == 0 and b % i == 0:
        cf.append(i)

print(cf)


dest = int(math.sqrt(cf))
cf_list = list(range(2, cf+1))
prime_list = []

for i in range(len(cf)):
    num_min = min(cf_list[i])
    if num_min >= dest:
        prime_list.extend(cf_list[i])
        break
    prime_list.append(num_min)

    j = 0

    while True:
        if i>= len(cf_list):
            break
        elif cf_list[i] % num_min == 0:
            cf_list.pop(i)
        j += 1

print(prime_list)
"""

Submission status: Accepted

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

#解法の大まかな流れ
#　AとBの素因数をそれぞれ計算し、And集合の長さを出す

#　数Nの素因数の算出方法
#  基本的には、Nを小さい数から順に割れるだけ割っていく（除算法）
#    割る数は素数だけでいい
# 課題：1～Aまでそれぞれ割って判定では計算量が足りない　A <= 10^12なので
# アイディア①：素数一覧表を作成して、一覧表に入っている数字だけで、割れるか判定
#  ⇒ 素数一覧表の作成の方が高コストになる可能性高い
# アイディア②： eratosthenesの篩の応用


def Soinsu(N):
    soinsu = set([1]) 
    if N > 1:
        # 偶数チェック（ここで引っ掛けられると割る数のカウントアップを倍にできるので)
        div2_flg = 1
        while div2_flg:
            if N % 2 == 0:
                soinsu.add(2)
                N = N/2
            else:
                div2_flg = 0
#         print("after 2: ",N)
        for i in range(3,int(N)+1,2):
#             print("i: ",i, " N: ",N)
        
            div_flg = 1
            while div_flg:
#                 print("   N: ",N)
                if N % i == 0:
                    soinsu.add(i)
                    N = N/i
                else:
                    div_flg = 0
            # 割る数の上限はN**(1/2)であることを適用
            if i**2 > N:
                break
        # 自分自身も入れる：これを入れないと片方がもう一方の素因数である場合を逃す
        soinsu.add(N)
        
    return(soinsu)
            
soi_A = Soinsu(A)
soi_B = Soinsu(B)
# print(soi_A)
# print(soi_B)
print(len(soi_A & soi_B))

Submission status: Accepted

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


while b:
    a, b = b, a % b

# aが最大公約数になっている

if a == 1 :
    print(1)
else :
    def factorization(a):
        arr = []
        temp = a
        for i in range(2, int(-(-a**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([a, 1])

        return arr

    print(int(len(factorization(a)) + 1))

Submission status: Accepted

Solution code:
import fractions

def devided(x):
    y = x
    devisors = 1
    for i in range(2, int((y**0.5)) + 1):
        if (x % i) == 0:
            devisors += 1
            while (x % i == 0):
                x //=  i
        else:
            continue
    if x > 1:
            devisors += 1
    return devisors

get = input().split()
A = int(get[0])
B = int(get[1])

C = fractions.gcd(A,B)

print(devided(C))

Submission status: Accepted

Solution code:
def trial_division(n):
    a = []  
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2   
    if n != 1: a.append(n)

    return a

from fractions import gcd

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

g = gcd(A,B)

L = trial_division(g)

D = {}

for i in L :
    if i not in D :
        D[i] = 1

print(len(D)+1)

Submission status: Accepted

Solution code:
# D - Disjoint Set of Common Divisors
from math import sqrt

def get_gcd(a, b):
    if b == 0:
        return a
    else:
        return get_gcd(b, 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

N, K = map(int, input().split())
gcd = get_gcd(N, K)
print(len(factorization(gcd)) + 1) if gcd > 1 else print(1)

Submission status: Accepted

Solution code:
def prime_factorize(n):
    a = [1]
    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())

Aprime = set(prime_factorize(A))
Bprime = set(prime_factorize(B))
ABintr = Aprime & Bprime

# print(Aprime, Bprime)
print(len(ABintr))

Submission status: Accepted

Solution code:
def GCD(a:int , b: int) -> int:
    return a if b == 0 else GCD(b, a % b)

from collections import defaultdict
def factorize(n: int) -> dict:
    f = defaultdict(int)
    tmp_n = n
    p = 2
    while tmp_n > 1 and p * p < n:
        while tmp_n % p == 0:
            f[p] += 1
            tmp_n = tmp_n // p
        p += 1 if p == 2 else 2

    if tmp_n != 1:
        f[tmp_n] += 1
    return f

a, b = map(int, input().split())
factors = factorize(GCD(a, b))

ans = len(factors) + 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import fractions

def main():
    A,B = map(int,input().split())
    C = fractions.gcd(A,B)
    Cn = prime_factorize(C)
    Cn = list(set(Cn))
    print(len(Cn)+1)

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

if __name__ == '__main__':
    main()

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

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

def main():
    A,B=map(int, input().split())
    ans = factorization(gcd(A,B))
    if ans[0][0] == 1:
        print(1)
    else:
        print(len(ans)+1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

Solution code:
#coding:utf-8
import fractions
#import math
import collections
#素因数分解
def prime_factorial(num):
    fact = []
    for i in range(2, int(num**0.5)+1):
        while num % i == 0:
            fact.append(i)
            num = num // i
    if num != 1:
        fact.append(num)
    return fact

if __name__ == "__main__":
    #最大公約数を素因数分解し、その個数＋1が答え
    a, b = map(int, input().split())
    #g = math.gcd(a, b)
    g = fractions.gcd(a, b)
    #print(g)
    #print(prime_factorial(g))

    c = collections.Counter(prime_factorial(g))
    print(len(list(c.keys())) + 1)

Submission status: Accepted

Solution code:
from math import sqrt, ceil

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

c_a = set()
c_b = set()

for i in range(1, ceil(sqrt(a))+1):
  if a % i == 0:
    c_a.add(i)
    if i > 1:
        while a % i == 0:
            a = a // i
if a != 1:
    c_a.add(a)

for j in range(1, ceil(sqrt(b))+1):
  if b % j == 0:
    c_b.add(j)
    if j > 1:
        while b % j == 0:
            b = b // j
if b != 1:
    c_b.add(b)

ans = c_a.intersection(c_b)

print(len(ans))

Submission status: Accepted

Solution code:
from collections import deque
A, B = [int(x) for x in input().split()]

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

t = gcd(A, B)
l = deque([1])
sqrt_t = int(t ** 0.5) + 1
for i in range(2, sqrt_t + 1):
  if t % i == 0:
    l.append(i)
    while t % i == 0:
      t //= i
      
l.append(t)
print(len(set(l)))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)
n = gcd(a, b)
ndiv = n
if n == 1:
    print(1)
else:
    i = 1
    primecount = 0
    divisor = False
    while True:
        i += 1
        while ndiv%i == 0:
            ndiv = ndiv//i
            divisor = True
        if divisor:
            primecount += 1
            divisor = False
            if ndiv == 1:
                break
        if ndiv != 1 and i*i > n:
            primecount += 1
            break
    print(primecount+1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)

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

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

g = gcd(A, B)
count = 0
for i in range(2, 10**6+3):
    if g%i == 0:
        count += 1
    while g%i == 0:
        g //= i
if g != 1:
    count += 1

print(count+1)

Submission status: Accepted

Solution code:
import fractions
import math
from collections import deque

def prime(x):
  px = []
  limit = int(math.sqrt(x))
  for i in range(2, limit+1):
    flag = False
    while x % i == 0:
      flag = True
      x = x // i
    if flag:
      px.append(i)
  if x != 1:
    px.append(x)
  return px

tmp = list(map(int,(input().split())))
a = tmp[0]
b = tmp[1]

pa = prime(a)
pb = prime(b)

cnt = 1
j = 0

for i in range(len(pa)):
  while j < len(pb) and pb[j] < pa[i]:
    j += 1
  if j == len(pb):
    break
  elif pb[j] == pa[i]:
    cnt += 1
  
print (cnt)

Submission status: Accepted

Solution code:
import math
 
 
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
  
 
a, b = map(int, input().split())
 
gcd = gcd(a, b)
 
res = set([1])
while gcd % 2 == 0: 
        res.add(2)
        gcd = gcd // 2
 
for i in range(3,int(math.sqrt(gcd))+1,2): 
    while gcd % i == 0: 
        res.add(i)
        gcd = gcd // i 
            
if gcd > 2: 
    res.add(gcd)
 
print(len(res))

Submission status: Accepted

Solution code:
# coding: utf-8
import fractions


def solve(arg: str) -> str:
    a, b = map(int, arg.split())
    div = [1]

    g = fractions.gcd(a, b)
    n = 2
    while n*n <= g:
        if g % n == 0:
            div.append(n)
            while g % n == 0:
                g = int(g/n)
        n += 1
    if g != 1:
        div.append(g)

    return str(len(div))


if __name__ == "__main__":
    print(solve(input()))

Submission status: Accepted

Solution code:
import collections

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

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())
N=gcd(A,B)
c = collections.Counter(prime_factorize(N))
print(len(list(c.keys()))+1)

Submission status: Accepted

Solution code:
#import sys

#input = sys.stdin.readline

#import heapq
import math
#import fractions

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

def main():
#    h,w,a,b = map(int, input().split())
    a,b=map(int,input().split())
    m=4
    k=1
    count=0

    if a>b:
        a,b=b,a
    sosu={1}
#    a = fractions.gcd(a,b)
    if a%2==0:
        sosu.add(2)
        while a%2==0:
            a//=2
    if a%3==0:
        sosu.add(3)
        while a%3==0:
            a//=3
#    print(d)
    c=math.sqrt(a)+1
 #   print(c)
    while m<=c and m!=1:
        if a%m==0:
            sosu.add(m)
            while a%m==0:
                a//=m

        m+=1
#    print(sosu)
    sosu.add(a)
#    print(sosu)

    for i in sosu:
        if b%i==0:
            count+=1
    print(count)
#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    gcd = fractions.gcd(a, b)
    cnt = 1
    for i in range(2, int(gcd ** 0.5) + 1):
        if gcd % i == 0:
            cnt += 1
            while True:
                if gcd % i == 0:
                    gcd //= i
                else:
                    break
    if gcd != 1:
        cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import fractions
import math
def x(n):
    a=[1]
    for i in range(2,int(math.sqrt(n))+1):
        while n%i==0:
            n//=i
            a.append(i)
    a.append(n)
    return a
A,B = map(int,input().split())
n=fractions.gcd(A,B)
print(len(set(x(n))))

Submission status: Accepted

Solution code:
#import sys

#input = sys.stdin.readline

#import heapq
import math
#import fractions

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

def main():
#    h,w,a,b = map(int, input().split())
    a,b=map(int,input().split())
    m=4
    k=1
    count=0

    if a>b:
        a,b=b,a
    sosu={1}
#    a = fractions.gcd(a,b)
    if a%2==0:
        sosu.add(2)
        while a%2==0:
            a//=2
    if a%3==0:
        sosu.add(3)
        while a%3==0:
            a//=3
#    print(d)
    c=math.sqrt(a)+1
 #   print(c)
    while m<=c and m!=1:
        if a%m==0:
            sosu.add(m)
            while a%m==0:
                a//=m

        m+=1
#    print(sosu)
    if a!=1:
        sosu.add(a)
#    print(sosu)

    for i in sosu:
        if b%i==0:
            count+=1
    print(count)
#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

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()
print(len(set(prime_factorize(a)) & set(prime_factorize(b)))+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

import fractions
x = fractions.gcd(A, B)
ans = prime_factorize(x)
print(len(set(ans))+1)

Submission status: Accepted

Solution code:
import fractions
import math

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


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

ans = set(trial_division(max_n))
print(len(ans))

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())
print(len(set(prime_factorize(a)) & set(prime_factorize(b)))+1)

Submission status: Accepted

Solution code:
#ABC142D
import math
import fractions
A,B = map(int,input().split())

g = fractions.gcd(A,B)

cnt = 0
first = True

for i in range(2,int(math.sqrt(g))+1):
    while g%i == 0:
        g //= i
        if first:
            cnt += 1
            first = False

    first = True

if g != 1:
    cnt += 1

print(cnt+1)

Submission status: Accepted

Solution code:
#import sys

#input = sys.stdin.readline

#import heapq
import math
import fractions

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

def main():
#    h,w,a,b = map(int, input().split())
    a,b=map(int,input().split())
    m=4
    k=1

    count=1
    if a>b:
        a,b=b,a
    sosu=set()
#    a = fractions.gcd(a,b)
    if a%2==0:
        sosu.add(2)
        while a%2==0:
            a//=2
    if a%3==0:
        sosu.add(3)
        while a%3==0:
            a//=3
#    print(d)
    c=math.sqrt(a)+1
 #   print(c)
    while m<=c and m!=1:
        if a%m==0:
            sosu.add(m)
            while a%m==0:
                a//=m

        m+=1
#    print(sosu)
    if sosu==set() and a!=1:
        sosu.add(a)
    if sosuhante(a) and a!=1:
        sosu.add(a)
#    print(sosu)

    for i in sosu:
        if b%i==0:
            count+=1
    print(count)
#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()