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:
from fractions import gcd

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

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

z = gcd(a,b)
print(len(prime_factor(z)))

Submission status: Accepted

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

n = fractions.gcd(A,B)
print(len(set(prime_factorize(n)))+1)

Submission status: Accepted

Solution code:
from fractions import gcd

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)

    if temp!=1:
        arr.append(temp)

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

    return arr
  
a = factorization(a)
b = factorization(b)
if (len(a)==1 and a[0] == 1) or (len(b)==1 and b[0] == 1):
  print(1)
else:
  print(len(set(a) & set(b)) + 1)

Submission status: Accepted

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

base=fractions.gcd(A,B)
count=1


for i in range(2,int(pow(base,1/2)+1)):
    if base==1:
        break
    else:
        if base%i==0:
            count+=1
            while base%i==0:
                base//=i
if base!=1:
    count+=1
print(count)

Submission status: Accepted

Solution code:
import math
from fractions import gcd

a, b = map(int, input().split())
cd = set()
ans = set()

'''
g = gcd(a, b)

for i in range(1, g+1):
    if a % i == 0 and b % i == 0:
        cd.add(i)
        '''

i =  1
a_set = set()

for i in range(1, int(math.sqrt(a)) + 1):
    if a % i == 0:
        a_set.add(i)
        a_set.add(a // i)
    i += 1

i = 1
b_set = set()

for i in range(1, int(math.sqrt(b)) + 1):
    if b % i == 0:
        b_set.add(i)
        b_set.add(b // i)
    i += 1

cd = set(a_set) & set(b_set)

for s in sorted(list(cd)):
    if s == 1:
        ans.add(s)
    else:
        for t in sorted(list(ans)):
            if t == 1:
                continue
            elif s % t == 0:
                break
        else:
            ans.add(s)

print(len(ans))

Submission status: Accepted

Solution code:
import math
import time
from collections import deque
from collections import defaultdict
from copy import deepcopy

mod = 10 ** 9 + 7
t = time.time()



def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


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

    a = set(soinsuu_bunkai(A))
    b = set(soinsuu_bunkai(B))

    ans = 1 # 1の場合
    for aa in a:
        if aa in b:
            ans+=1

    print(ans)

main()

Submission status: Accepted

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

a_div = []
b_div = []

i = 1
while i * i < a + 1:
    if a % i == 0:
        a_div.append(i)
        a_div.append(a // i)
    i += 1
i = 1
while i * i < b + 1:
    if b % i == 0:
        b_div.append(i)
        b_div.append(b // i)
    i += 1

common = set(a_div) & set(b_div)

disjoint = set()
for num in sorted(list(common)):
    if num == 1:
        disjoint.add(num)
    else:
        for disnum in sorted(list(disjoint)):
            if disnum == 1:
                continue
            elif num % disnum == 0:
                break
        else:
            disjoint.add(num)

print(len(disjoint))

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


fa = set([x for x, y in factorization(a)]+[1])
fb = set([x for x, y in factorization(b)]+[1])
ans = 0
for x in fa:
    if x in fb:
        ans += 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)

G = gcd(A, B)



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

prime = prime_factorize(G)

print(len(prime)+1)

Submission status: Accepted

Solution code:
#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
A,B = list(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

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

Submission status: Accepted

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

import math
#試し割法
def trial_division(n):
    #素因数を格納するリスト
    factor = [1]
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    factor.append(n)
    return factor

A_ = trial_division(A)
B_ = trial_division(B)
c = list(set(A_))
d = list(set(B_))

count = 0
for i in range(len(c)):
    for j in range(len(d)):
        if c[i] == d[j]:
            count += 1

print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict

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


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


d = gcd(A, B)
# print(d)


def f(v):
    dic = defaultdict(int)
    if v == 1:
        dic[1] = 1
        return dic
    for i in range(2, v):
        if i * i > v:
            break
        while v % i == 0:
            v //= i
            dic[i] += 1
    if v != 1:
        dic[v] += 1
    dic[1] = 1
    return dic


divisor = f(d)
# print(divisor)
print(len(divisor))

Submission status: Accepted

Solution code:
import random

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

def is_prime(q, k=5):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q & 1 == 0: return False
    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1
    for i in range(k):
        a = random.randint(1, q-1)
        t = d
        y = pow(a, t, q)
        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

a, b = map(int, input().split())
comNum = list(set(make_divisors(a)) & set(make_divisors(b)))
ans = 1
for i in comNum:
    if is_prime(i):
        ans += 1
print(ans)

Submission status: Accepted

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

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

    if tmp != 1:
        arr.append(tmp)

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

    return arr

print(len(factorization(ab)))

Submission status: Accepted

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

faca=fac(a)
facb=fac(b)

Fa=set()
Fb=set()
for i in faca:
      Fa.add(i[0])
for i in facb:
      Fb.add(i[0])
Fu=Fa&Fb
if a==1 or b==1:
      print(1)
else:
      print(len(Fu)+1)

Submission status: Accepted

Solution code:
from math import sqrt
from fractions import gcd

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

ans = 1

g = gcd(A, B)

for i in range(2, 1 + int(sqrt(g))):

    if g % i == 0:
        ans += 1

        while g % i == 0:
            g //= i

if g != 1:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
def prime_pair(n):
    pairs = {}
    tmp = n
    for i in range(2, n):
        if i * i > n:
            break
        if tmp % i != 0:
            continue
        ex = 0
        while tmp % i == 0:
            ex += 1
            tmp /= i
        pairs[i] = ex
    if tmp != 1:
        pairs[int(tmp)] = 1
    return pairs

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


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

ppa = prime_pair(A)
ppb = prime_pair(B)

g = gcd(A,B)
ppg = prime_pair(g)

print(len(ppg.keys())+1)

Submission status: Accepted

Solution code:
a,b = list(map(int,input().split()))
l = []

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

dl = list(set(make_divisors(a)) & set(make_divisors(b)))
dl.sort(reverse = True)

#ユークリッド
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

del dl[dl.index(1)]
ans = [1]
flag=True
j=0
while(j<len(dl)):
    x = dl.pop(0)
    for i in dl:
        if gcd(x,i)==1:
            next
        else:
            flag=False
            break
    if flag:
        ans.append(x)
    flag=True
print(len(ans))

Submission status: Accepted

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

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

    primes = [1] + list(set(ap) & set(bp))

    print(len(primes))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
a, b = [int(i) for i in input().split()]
c = gcd(a, b)

def p(x):
    a=[]
    i=2
    while True:
        if x % i == 0:
            j=0
            while x % i == 0:
                x //= i
                j += 1
            a.append((i, j))
        if i * i > x:
            break
        i += 1
    if x != 1:
        a.append((x,1))
    return a

print(len(p(c))+1)

Submission status: Accepted

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


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


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

Submission status: Accepted

Solution code:
from fractions import gcd
A, B=map(int, input().split())
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)

  # divisors.sort()
  return divisors

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
ans=0
for x in set(make_divisors(A))&set(make_divisors(B)):
  if is_prime(x):
    ans+=1

#print(set(make_divisors(A))&set(make_divisors(B)))
print(ans+1)

Submission status: Accepted

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

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

print(len(prime_factorize(AB))+1)

Submission status: Accepted

Solution code:
def prefactor(x):
  ret = set()
  for i in range(2, int(x**0.5)+1):
    if x%i==0: ret.add(i)
    while x%i==0: x //= i
  if x>1: ret.add(x)
  return ret
    

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

Submission status: Accepted

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

a, b = map(int, input().split())
ap = decomposition_prime(a)
bp = decomposition_prime(b)

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

Submission status: Accepted

Solution code:
#素因数分解
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

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

arr=[i for i in a if i in b]
print(len(arr)+1)

Submission status: Accepted

Solution code:
import math

def Sieve_of_Eratosthenes(N):
    if N<2:
        prime = [False for i in range(N+1)]
        return prime
 
    prime = [True for i in range(N+1)]
    prime[0] = False
    prime[1] = False
 
    for i in range(2, int(N**0.5)+1):
        if prime[i]:
            for j in range(i*2, N+1, i):
                prime[j] = False
 
    return prime


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

a,b=map(int,input().split())
n=gcd(a,b)
prime=Sieve_of_Eratosthenes(int(math.sqrt(n))+2)
ans=1
x=n
for p in range(len(prime)):
    if prime[p]:        
        if x==1:
            break
        if x%p==0:
            ans+=1
            while x%p==0:
                x=x//p

if x!=1: ans+=1
print(ans)

Submission status: Accepted

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

C = gcd(A, B)


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

print(len(prime_factorize(C)) + 1)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

X, Y = map(int, input().rstrip().split())

# nを素因数分解
# 各素因数を数え上げる場合はcounterを使うとよい
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(1 + len(set(prime_factorize(X)) & set(prime_factorize(Y))))

Submission status: Accepted

Solution code:
import math
from collections import defaultdict


def trial_division(n):
    factor = defaultdict(int)
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            factor[num] += 1
    factor[n] += 1
    if 1 not in factor.keys():
        factor[1] += 1
    return factor


a, b = map(int, input().split())
ans = 0
for i in trial_division(a).keys():
    if i in trial_division(b).keys():
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from fractions import gcd
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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def factorize(x):
    ret = []
    i = 2
    while i * i <= x:
        while x % i == 0:
            x //= i
            ret.append(i)
        i += 1
    if x > 1:
        ret.append(x)
    return ret

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

A, B = map(int, input().split())
C = gcd(A, B)
print(len(set(factorize(C))) + 1)

Submission status: Accepted

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


def factorization_in_prime_number(x):
    prime_factor = []
    if x % 2 == 0:
        prime_factor.append(2)
    while x % 2 == 0:
        x //= 2
    m = int(x**.5) + 1
    for i in range(3, m, 2):
        if x % i == 0:
            prime_factor.append(i)
        while x % i == 0:
            x //= i
    if x != 1:
        prime_factor.append(x)
    # x=1 の時はからのリストを返す
    return prime_factor


a_factor = factorization_in_prime_number(a)
b_factor = factorization_in_prime_number(b)
ans = len(set(a_factor) & set(b_factor)) + 1
print(ans)

Submission status: Accepted

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

a = factorization(A)
b = factorization(B)

c = 1
for i in range(len(a)):
    for j in range(len(b)):
        if a[i][0] == b[j][0]:
            if a[i][0] != 1:
                c += 1

print(c)

Submission status: Accepted

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


def factorization_in_prime_number(x):
    prime_factor = []
    if x % 2 == 0:
        prime_factor.append(2)
    while x % 2 == 0:
        x //= 2
    m = int(x**.5) + 1
    for i in range(3, m, 2):
        if x % i == 0:
            prime_factor.append(i)
        while x % i == 0:
            x //= i
    if x != 1:
        prime_factor.append(x)
    return prime_factor


a_factor = factorization_in_prime_number(a)
b_factor = factorization_in_prime_number(b)
ans = len(set(a_factor) & set(b_factor)) + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B = map(int,input().split())
A_sosu = []
B_sosu = []
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_sosu = set(prime_factorize(A))
B_sosu = set(prime_factorize(B))
cnt = 0
for a in A_sosu:
    if(a in B_sosu):
        cnt += 1
print(cnt+1)

Submission status: Accepted

Solution code:
import sys
import numpy as np


def input():
    return sys.stdin.readline()[:-1]


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


def factorize(n):
    res = dict()
    for i in range(2, int(np.sqrt(n)) + 10):
        if n % i:
            continue
        res.setdefault(i, 0)
        while (n % i == 0):
            n //= i
            res[i] += 1
    if n != 1:
        res.setdefault(n, 1)
    return res


def solve():
    a, b = map(int, input().split())
    n = gcd(a, b)
    print(len(factorize(n))+1)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from fractions import gcd
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(n):
    if n == 1: return False
    for k in range(2, int(n**0.5)+1):
        if n % k == 0:
            return False
    return True

a, b = map(int, input().split())
# a, b = 10**12, 10**12
ans = 0
GCD = gcd(a, b)
# GCD = 10**12
GCD_list = make_divisors(GCD)
# print(GCD_list)

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

print(ans + 1)

Submission status: Accepted

Solution code:
def m_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)
    return divisors

a,b = map(int, input().split())
lis = list(set(m_div(a)) & set(m_div(b)))
lis.sort()

anslis=[]

for num in lis[1:]:
    prime=True
    for p in anslis:
        if num % p == 0:
            prime=False
    if prime:
        anslis.append(num)
print(len(anslis)+1)

Submission status: Accepted

Solution code:
from fractions import gcd
#from math 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
a,b=map(int,input().split())
m=gcd(a,b)
P=prime_factorize(m)
print(1+len(list(set(P))))

Submission status: Accepted

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

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

def get_sieve_of_eratosthenes(n):#n以下の素数のリストを返す
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
    return(data)

n=gcd(A,B)
ans = 1
if n==1:
    print(1)
else:
    #plist = get_sieve_of_eratosthenes(n)
    #for p in plist:
    for p in range(2,int(n**0.5)+3):
        if n%p==0:
            ans+=1
            while n%p==0:
                n = n//p
    if n!=1:
        ans+=1
    print(ans)

Submission status: Accepted

Solution code:
A, B = map(int, input().split())
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
N = gcd(A,B)

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
from fractions import gcd
def divisor(N):
    # 約数列挙
    divs = []
    for i in range(1, int(N**0.5)+1):
        if N % i == 0:
            divs.append(i)
            if i != N // i:
                divs.append(N//i)
    return divs
def eratosthenes(N):
    # 素数判定
    flag = True
    for i in range(2, int(N**0.5) + 1):
        if N % i == 0:
            flag = False
            break
    return flag

A, B = map(int, input().split())
A_divs = divisor(A)
B_divs = divisor(B)
ans = 1
L = list(set(A_divs) & set(B_divs))
ans = 0
for i in range(len(L)):
    if eratosthenes(L[i]):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
import fractions

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

gcd = fractions.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

div = make_divisors(gcd)
ans = 1
for i in range(1,len(div)) :
  check = 0
  for j in range(2,math.floor(math.sqrt(div[i]))+1) :
    if div[i]%j == 0 :
      check = 1
      break
  if check == 0 :
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()

def cf(x1,x2):
    cf=[]
    for i in range(1, min(x1,x2) + 1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

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 primes_for(n):
   is_prime = [True] * (n + 1)
   is_prime[0] = False
   is_prime[1] = False
   for i in range(2, n + 1):
       for j in range(i * 2, n + 1, i):
           is_prime[j] = False
   return [i for i in range(n + 1) if is_prime[i]]

a = make_divisors(A)
b = make_divisors(B)

kouyaku = (set(a) & set(b))

# p = primes_for(10**6)
# p.append(1)

# print(len((set(kouyaku) & set(p))))

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

wa = 0
for i in kouyaku:
	if is_prime(i):
		wa += 1
print(wa)

Submission status: Accepted

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

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

def divisor(n): #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

#引数nが素数かどうかを判定
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

A, B = MAP()
a = divisor(A)
b = divisor(B)
a = set(a)
b = set(b)
kouyaku = a & b

ans = 1
for y in kouyaku:
    if is_prime(y):
        ans += 1
print(ans)

Submission status: Accepted

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

import fractions
c = fractions.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
print(len(set(prime_factorize(c))) + 1)

Submission status: Accepted

Solution code:

# nを素因数分解したリストを返す
def decomposition_prime(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(int(n))
    return table

A, B = map(int, input().split())
Ap = set(decomposition_prime(A))
Bp = set(decomposition_prime(B))
print(len(Ap & Bp)+1)

Submission status: Accepted

Solution code:
import math 
import bisect
from collections import deque
a,b = map(int, input().split())
def pf(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_s = pf(a)
a_s = list(set(a_s))
b_s = pf(b)
count = 0

for i in range(len(a_s)):
    if a_s[i] in b_s: count += 1 

print(count + 1) # 1