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 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)
    m=4
    k=1

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

        m+=1
#    print(sosu)
    if sosub==set() and b!=1:
        sosub.add(b)
    if sosuhante(b) and b!=1:
        sosub.add(b)
#    print(sosu,sosub)
    for i in sosu:
        if i in sosub:
            count+=1
    print(count)
#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(len(set(factorize(a))&set(factorize(b)))+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)
    count+=len(sosu)
    print(count)
#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

def get_divisor(n: int) -> list:
    divisor = []
    for i in range(1, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            divisor.append(i)
            if i != n // i:
                divisor.append(n // i)
    divisor.sort()
    return divisor

a, b = map(int, input().split())
divisor =  get_divisor(GCD(a, b))

ans = 1
used = [0] * len(divisor)
used[0] = 1
for i in range(1, len(divisor)):
    if used[i] == 0:
        ans += 1
        for j in range(i+1, len(divisor)):
            if used[j] == 0 and divisor[j] % divisor[i] == 0:
                used[j] = 1

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
import sys
input = sys.stdin.readline


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


def main():
    A, B = map(int, input().split())

    P = set(prime_decomposition(gcd(A, B)))
    
    print(len(P) + 1)
    

 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

while B > 0:
    A, B = B, A % B
N = A

ans = 1
i = 2
while i * i <= N:
    if N % i == 0:
        while N % i == 0:
            N //= i
        ans += 1
    i += 1
if N > 1:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

while B > 0:
    A, B = B, A % B
N = A

ans = 1
for i in [2] + list(range(3, int(math.sqrt(N)) + 2, 2)):
    if N % i == 0:
        while N % i == 0:
            N //= i
        ans += 1
if N > 1:
    ans += 1
print(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())
A_list = set(prime_factorize(A))
B_list = set(prime_factorize(B))

print(len(A_list & B_list) + 1)

Submission status: Accepted

Solution code:
b = list(map(int, input().split()))
def fac(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

la=fac(b[0])
lb=fac(b[1])


print(len(set(la) & set(lb))+1)

Submission status: Accepted

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

def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
n = 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

ans = set(prime_factorize(n))
print(len(ans)+1)

Submission status: Accepted

Solution code:
def gcd(x, y):
    if y == 0 :
        return x
    else:
        return gcd(y,x%y)
def prime(x):
    global  ans
    m = x ** (0.5)
    for i in range(2,int(m+1)):
        if x % i == 0 :
            while True:
                if x % i != 0 :
                    break
                else:
                    x = (x//i)
            ans +=1
    if x != 1 :
        ans += 1
    return ans
A,B = map(int,input().split())
t = gcd(A,B)
ans = 1
print(prime(t))

Submission status: Accepted

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

def pf(n):
    a, odd = {1}, 3
    while n%2==0:
        a.add(2)
        n //= 2
    while odd**2<=n:
        if n%odd==0:
            a.add(odd)
            n //= odd
        else:
            odd += 2
    a.add(n)
    return a

def main():
    a, b = map(int, input().split())
    print(len(pf(gcd(a, b))))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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 isprime(n):
    sup = int(n**0.5)
    for i in range(2, sup+1):
        if n%i==0:
            return False
    return True

A, B = map(int, input().split())
g = gcd(A, B)
divs = make_divisors(g)
ans = 0
for d in divs:
    ans += 1 if isprime(d) else 0
print(ans)

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

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

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

Submission status: Accepted

Solution code:
def gcd(x, y):
    m = max(x, y)
    n = min(x, y)
    z = y
    while m % n == 0:
        z = x % y
        x = y
        y = z
    return z

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

x, y = map(int, input().split())

z = prime_factorize(x)
w = prime_factorize(y)

zz = set(z) & set(w)
print(len(zz)+1)

Submission status: Accepted

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

import math

if A < B:
    A, B = B, A
    
while A % B != 0:
    A, B = B, A%B
    
ans = 1

for i in range(2, int(math.sqrt(B))+1):
    if B % i == 0:
        ans += 1
        
        while B % i == 0:
            B //= i
            
if B > 1:
    ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, 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


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


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

g = gcd(A, B)
d = make_divisors(g)

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
import collections
import math
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])

    
    return arr
Gcd = fractions.gcd(A,B)
ans = factorization(Gcd)
print(len(ans)+1)

Submission status: Accepted

Solution code:
a, b = [int(i) for i in input().split()]
small = min(a, b)
big = max(a, b)

import sys

if small == 1:
    print(1)
    sys.exit(0)

import math
import collections

# FYI: https://ja.wikipedia.org/wiki/%E8%A9%A6%E3%81%97%E5%89%B2%E3%82%8A%E6%B3%95
def prime_factorization(num, divisors=None):
    if num <= 1:
        assert False
    factors = []

    # divisorsを使い回せるようにする。
    #   - 二度生成した場合にかかる時間が許容できない場合
    #   - エラトステネスの篩などで素数テーブルを既に持っている場合
    if not divisors:
        divisors = [2] + [i for i in range(3, int(math.sqrt(num)) + 1) if i % 2 != 0]

    for d in divisors:
        # divisorsを引数で与えた場合のみ起こりうる
        if num < d:
            break
        while num % d == 0:
            factors.append(d)
            num //= d

    if num != 1:
        factors.append(num)
    return factors

#divisors = [2] + [i for i in range(3, int(math.sqrt(big)) + 1) if i % 2 != 0]
#small_factors = set(prime_factorization(small, divisors))
#big_factors = set(prime_factorization(big, divisors))
small_factors = set(prime_factorization(small))
big_factors = set(prime_factorization(big))

print(len(small_factors.intersection(big_factors)) + 1)

Submission status: Accepted

Solution code:
a, b = [int(i) for i in input().split()]
small = min(a, b)
big = max(a, b)

import sys

if small == 1:
    print(1)
    sys.exit(0)

import math
import collections

# FYI: https://ja.wikipedia.org/wiki/%E8%A9%A6%E3%81%97%E5%89%B2%E3%82%8A%E6%B3%95
def prime_factorization(num, divisors=None):
    if num <= 1:
        assert False
    factors = []

    # divisorsを使い回せるようにする。
    #   - 二度生成した場合にかかる時間が許容できない場合
    #   - エラトステネスの篩などで素数テーブルを既に持っている場合
    if not divisors:
        divisors = [2] + [i for i in range(3, int(math.sqrt(num)) + 1) if i % 2 != 0]

    for d in divisors:
        # divisorsを引数で与えた場合のみ起こりうる
        if num < d:
            break
        while num % d == 0:
            factors.append(d)
            num //= d

    if num != 1:
        factors.append(num)
    return factors

divisors = [2] + [i for i in range(3, int(math.sqrt(big)) + 1) if i % 2 != 0]
small_factors = set(prime_factorization(small, divisors))
big_factors = set(prime_factorization(big, divisors))

print(len(small_factors.intersection(big_factors)) + 1)

Submission status: Accepted

Solution code:
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
    
a,b = map(int,input().split())

aset = set(divisor(a))
bset = set(divisor(b))

cset = aset & bset
clist = list(cset)
"""
if len(clist) == 1:
    print(1)
    exit()

coprime = [1]
coprime.append(clist[1])

#print(clist)

for j in range(2,len(clist)):
    for k in range(1,len(coprime)):
        if clist[j] % coprime[k] == 0:
            break
    else:
        coprime.append(clist[j])

#print(coprime)
print(len(coprime))
"""

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

cop = 1
for j in range(1,len(clist)):
    if is_prime(clist[j]) == True:
        cop += 1

print(cop)

Submission status: Accepted

Solution code:
def prime_factorize(n):
    a = set([1])
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    a.add(n)
    return a
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
a, b = list(map(int, input().split()))
x = gcd(a, b)
print(len(prime_factorize(x)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import fractions

# divisor
def div(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 factor(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())
    d = fractions.gcd(A, B)
    #print('d={}'.format(d))

    if d == 1:
        print(1)
    else:
        print(1 + len(factor(d)))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A, B = sorted([int(i) for i in input().split()])

res = 1
for i in range(2, int(B**0.5)+1):
    if B % i == 0:
        if A % i == 0:
            for j in range(2, int(i**0.5)+1):
                if i % j == 0:
                    break
            else:
                res += 1
        t = B // i
        if t != i and A % t == 0:
            for j in range(2, int(t**0.5)+1):
                if t % j == 0:
                    break
            else:
                res += 1

print(res if res > 1 else (1 if (A == B == 1) or A != B else 2))

Submission status: Accepted

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

S = list(map(int,input().split()))
A = min(S)
B = max(S)
  
C = collections.Counter(prime_factorize(A))
count = 1
for p in C.keys():
    if B % p == 0:
        count += 1
print(count)

Submission status: Accepted

Solution code:
from fractions import gcd
from math import sqrt
import sys
def input() -> str:
    return sys.stdin.readline()
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            divisors.add(n//i)
    return list(divisors)
def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True
a, b = map(int, input().split())
print(len([div for div in make_divisors(gcd(a, b)) if is_prime(div)]) + 1)

Submission status: Accepted

Solution code:
def div(N):
    ans = []
    for i in range(1, int(N ** 0.5) + 1):
        if N % i == 0:
            ans.append(i)
            if N // i != i:
                ans.append(N // i)
    ans.sort()
    return ans
import fractions

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

g=fractions.gcd(A,B)

if g==1:
    print(1)
    exit()
cnt=0
di=div(g)

for i in di:
    f=True
    for j in range(2,int(i**0.5)+1):
        if i%j==0:
            f=False
            break
    if f:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin


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


def factorization(a):
    if a < 2:
        return []
    fac = []
    lim = int(a ** 0.5)
    i = 2
    while a > 1 and i <= lim:
        n = 0
        while a % i == 0:
            a //= i
            n += 1
        if n > 0:
            fac += [(i, n)]
        i += 1
    if a > 1 or fac == []:
        fac += [(a, 1)]
    return fac


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

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

Submission status: Accepted

Solution code:
A, B = [int(v) for v in input().split(' ')]

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2

    i = 3
    while i * i <= n:
        if n % i == 0:
            a.append(i)
            n //= i
        else:
            i += 2

    if n != 1:
        a.append(n)
    return a

a_fact = prime_factorize(A)
b_fact = prime_factorize(B)

print(len(set(a_fact) & set(b_fact)) + 1)

Submission status: Accepted

Solution code:
import fractions

A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
arr = []
temp = D
if D == 1:
  pass
else:
  for i in range(2, int(-(-D**0.5//1)+1)):
    if temp%i == 0:
      while temp%i == 0:
        temp //= i
      arr.append(i)
  if temp != 1:
    arr.append(D)
print(len(arr)+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())
apri = set(prime_factorize(a))
bpri = set(prime_factorize(b))
print(len(apri & bpri)+1)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

def main():
    A,B = map(int, input().split())
    ps = set(prime_factorize(A)) & set(prime_factorize(B))
    print(len(ps)+1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

    primeFactorA = prime_factorize(A)
    primeFactorB = prime_factorize(B)

    commonFactor = [1]
    for f in primeFactorB:
        if f in primeFactorA:
            commonFactor.append(f)
    
    print(len(commonFactor))


def prime_factorize(num):
    a = set() 
    while num % 2 == 0:
        a.add(2)
        num //= 2
    
    f = 3
    while f * f <= num:
        if num % f == 0:
            a.add(f)
            num //= f
        else:
            f += 2
    if num != 1:
        a.add(num)
    
    return a

if __name__ == '__main__':
    solve()

Submission status: Accepted

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




def getPrimeFactorsList(num):
  pn = 2 #素数は2から
  pflist = [] #素因数のリスト
  while pn * pn <= num: #√numまで調べる
    while num % pn == 0: #現在の素数で割り切れる範囲でループ
      num = num / pn
      pflist.append(pn)
    pn += 1 #割り切れなくなったら次の素数へ
  if num > 1:
    pflist.append(int(num))
    
  return pflist

pf_A = getPrimeFactorsList(A)
pf_B = getPrimeFactorsList(B)
ans = len(set(pf_A) & set(pf_B)) + 1
print(ans)

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


    return arr

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

Submission status: Accepted

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


A_yaku = []

now = 0

a = 2

while A >= a*a:
  if A%a == 0:
    if a != now:
      A_yaku.append(a)
      now = a
    A /= a
  else:
    a +=1

if A != now and A != 1:
  A_yaku.append(A)

B_yaku = []

now = 0

a = 2

while B >= a*a:
  if B%a == 0:
    if a != now:
      B_yaku.append(a)
      now = a
    B /= a
  else:
    a +=1

if B != now and B != 1:
  B_yaku.append(B)

count = 0

if(len(A_yaku) >= len(B_yaku)):
  for i in range(0,len(B_yaku)):
    if(B_yaku[i] in A_yaku):
      count += 1
else:
  for i in range(0,len(A_yaku)):
    if(A_yaku[i] in B_yaku):
      count += 1

count += 1

print(count)

Submission status: Accepted

Solution code:
def d_disjoint_set_of_common_divisors():
    from fractions import gcd
    A, B = [int(i) for i in input().split()]

    def prime_factorization_dict(n):
        """nを素因数分解したときの素数とその指数の辞書"""
        from collections import defaultdict
        if n == 1:
            return {2: 0}  # 1は素数の0乗の積とみなす
        i, table = 2, defaultdict(int)
        while i**2 <= n:
            while n % i == 0:
                table[i] += 1
                n //= i
            i += 1
        if n > 1:
            table[n] = 1
        return table
    g = gcd(A, B)
    return len(prime_factorization_dict(g).keys()) + 1 if g > 1 else 1

print(d_disjoint_set_of_common_divisors())

Submission status: Accepted

Solution code:
import math
import sys

M=list(map(int,input().split()))


def prime(i):
  k=[]
  num=i
  j=2
  while j*j<=num:
    if i%j==0:
      i//=j
      k.append(j)
    else:
      j+=1
  if i!=1:
    k.append(i)
  k.append(1)
  return k

a=set(prime(M[0]))
b=set(prime(M[1]))
print(len(list(a&b)))

Submission status: Accepted

Solution code:
from collections import Counter
from fractions import gcd

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__":
    A, B = list(map(int, input().split()))
    x = gcd(A, B)
    print(len(Counter(prime_factorize(x)).keys())+1)

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
if x < y: x, y = y, x
while x % y != 0:
    x, y = y, x % y
ans=1
for i in range(2,int(y**0.5)+1):
    if y%i==0:
        ans+=1
        while y%i==0:
            y//=i
if y>1:ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math

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

# 素因数の個数(cnt)は使わないので省いた
def prime_factorize(n):
    res = [] # 結果を格納
    tmp = n # tmpにnをコピーしておく

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

    # tmpに余った素数の処理
    if tmp != 1:
        res.append(tmp)

    # 何も割れなかったらnは素数なのでそのまま入れておく
    if res == [] and n != 1:
        res.append(n)

    return(res)

A_fac = set(prime_factorize(A))
B_fac = set(prime_factorize(B))

C = A_fac & B_fac
ans = len(C) + 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from fractions import gcd

#coding:utf8
import random

def is_prime3(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True
ans=0

a,b=map(int,input().split())
c=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
s=make_divisors(c)
for i in s:
    ans=ans+is_prime3(i)
print(ans+1)

Submission status: Accepted

Solution code:
# 190928 D

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 = list(map(int,input().split()))
soA = prime_factorize(A)
soB = prime_factorize(B)
output = []
for i in range(len(soA)):
    if soA[i] in soB:
        output.append(soA[i])

print(len(list(set(output))) + 1)

Submission status: Accepted

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

a,b=map(int,input().split())
x=gcd(a,b)
if(x==1):
    print(1)
    exit()
s=[]
i=2
while(i*i<=x):
    if(x%i==0):
        s.append(i)
        x/=i
    else:
        i+=1
s.append(x)
print(len(set(s))+1)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import math
import fractions
input = sys.stdin.readline


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())
x = fractions.gcd(a, b)
check_list = []
i = 2

while x % 2 == 0:
    check_list.append(2)
    x //= 2
i = 3
while i * i <= x:
    if x % i == 0:
        check_list.append(i)
        x //= i
    else:
        i += 2
if x != 1:
    check_list.append(x)

print(len(set(check_list))+1)

Submission status: Accepted

Solution code:
from sys import stdin

input = stdin.readline
mi = lambda: map(int, input().split())
lmi = lambda: list(mi())
si = lambda: input().strip('\a')
ii = lambda: int(input())


a, b = mi()
ap = set()
for i in range(2, int(a**.5) + 1):
    while a%i == 0:
        ap.add(i)
        a/=i
if a != 1:
    ap.add(a)

bp = set()
for i in range(2, int(b**.5) + 1):
    while b%i == 0:
        bp.add(i)
        b/=i
if b != 1:
    bp.add(b)

print(len(bp.intersection(ap))+1)

Submission status: Accepted

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


def gcd(a, b):
    while b:
        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


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

Submission status: Accepted

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

for i in range(2, int(math.sqrt(g))+1):
  if g%i == 0:
    ans += 1
    while True:
      g //= i
      if g%i != 0:
        break
if (g != 1):
  ans += 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import math
import fractions
input = sys.stdin.readline


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())
x = fractions.gcd(a, b)
check_list = []
i = 2
"""
while (1):
    flag = False
    if i > x:
        break
    while(x % i == 0):
        x /= i
        flag = True

    if flag == True:
        check_list.append(i)
    i += 1
"""
while x % 2 == 0:
    check_list.append(2)
    x //= 2
i = 3
while i * i <= x:
    if x % i == 0:
        check_list.append(i)
        x //= i
    else:
        i += 2
if x != 1:
    check_list.append(x)

print(len(set(check_list))+1)

# print(check_list)
"""
ans = 1
for check in check_list:
    if is_prime(check):
        ans += 1

print(ans)
"""

Submission status: Accepted

Solution code:
import fractions
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())
ans = fractions.gcd(A,B)
lists = []
cnt = 0
ansr = prime_factorize(ans)
print(len(set(ansr))+1)

Submission status: Accepted

Solution code:
import fractions

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

#print(A,B)

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

g = fractions.gcd(A,B)
#print(g)
p = prime_factorize(g)
p = list(set(p))
#print(p)
print(len(p)+1)

Submission status: Accepted

Solution code:
from fractions import gcd
def f(n):
    tmp = n
    cnt = 0
    i = 2
    while i <= n**0.5 + 1:
        if tmp < i:
            break
        if tmp % i == 0:
            cnt += 1
            while tmp % i == 0:
                tmp //= i
        i += 1
    if tmp != 1:
        cnt += 1
    return cnt

A, B = map(int, input().split())
g = gcd(A, B)
ans = f(g) + 1
print(ans)