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:
# 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:
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):
    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 as fra
a,b=map(int,input().split())
c=fra.gcd(a,b)
cnt=0
for i in range(2,int(c**0.5)+1):
    if(c%i==0):
        cnt+=1
        while(True):
            c//=i
            if(c%i != 0):
                break
if(c!=1):
    cnt+=1
print(cnt+1)

Submission status: Accepted

Solution code:
import fractions
A, B = map(int, input().split())
MAX = 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(MAX)))+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_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


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

Submission status: Accepted

Solution code:
n = list(map(int, input().split()))

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

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

    return arr

d = gcd(n[0],n[1])

c = factorization(d)


print(len(c))

Submission status: Accepted

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

if n==1:
  print(1)
  exit()
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

print(len(factorization(n))+1)

Submission status: Accepted

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

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())
gcd_AB = gcd(A, B)
# 素因数分解
p_list = prime_factorize(gcd_AB)
#print(p_list)
print(len(set(p_list))+1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

while m:
    n, m = m, n % m

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

if pf == {}:
    print(1)
else:
    print(len(pf)+1)

Submission status: Accepted

Solution code:
import collections
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 set(a)


A, B = list(map(int, input().split()))
print(len(prime_factorize(fractions.gcd(A, B))) + 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 count_prime(n):
    i = 2
    primes = set()
    while i * i <= n:
        while n % i == 0:
            n /= i
            primes.add(i)
        i += 1
    if n > 1:
        primes.add(n)
    return len(primes)


print(count_prime(gcd(a, b)) + 1)

Submission status: Accepted

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

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


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

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)

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

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

    return arr

#import numpy as np

a, b = map(int, input().split())
if a==1 and b==1:
    print(1)
else:
    #print(factorization(a))
    prime_a = factorization(a)
    prime_b = factorization(b)
    #print(prime_a, prime_b)
    print(1+len(set(prime_a)&set(prime_b)))

Submission status: Accepted

Solution code:
import math
import fractions

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

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

a, b = map(int, input().split())
g = fractions.gcd(a, b)
l = make_divisors(g)
count = 0
for e in l:
  if is_one_or_prime(e):
    count += 1
print(count)

Submission status: Accepted

Solution code:
import math
ab = list(map(int,input().split()))
a = ab[0]
b = ab[1]
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
a_div = make_divisors(a)
b_div = make_divisors(b)

def is_prime(n):
    if n == 1: return True
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True
def primer(n):
    an = []
    for i in range(0,len(n)):
        if is_prime(n[i]) == True:
            an.append(n[i])
    return an
a_pri = primer(a_div)
b_pri = primer(b_div)
c =[]
for i in range(0,len(a_pri)):
    if b_pri.count(a_pri[i]) > 0:
        c.append(a_pri[i])
print(len(c))

Submission status: Accepted

Solution code:
def trial_divishion(n):
    factors = []

    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            factors.append(i)
            
    if n != 1:
        factors.append(n)
        
    return factors
    
a, b = map(int, input().split())
print(len(set(trial_divishion(a)) & set(trial_divishion(b))) + 1)

Submission status: Accepted

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


def prime_factorize(n):
    """Return the prime factorization of n > 1.
    >>> prime_factorize(36)
    [2, 2, 3, 3]
    """
    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):
    pf_a = set(prime_factorize(a))
    pf_b = set(prime_factorize(b))
    return len(pf_a & pf_b) + 1


print(main(a, b))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
a, b = min(a, b), max(a, b)
cd = []
for i in range(1,int(a**0.5)+1):
    if a % i == 0:
        if b % i == 0:
            cd.append(i)
        if i != a // i and b % (a//i) == 0:
            cd.append(a//i)
ans = 1
for n in cd:
    prime = True
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            prime = False
            break
    if n == 1:
        prime = False
    if prime == True:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
import fractions
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 ** .5) + 1):
        if p % i == 0:
            return False
    return True

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

g = fractions.gcd(A, B)

div = make_divisors(g)
ans = 1
for i in div:
    if is_prime(i):
        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())
gcd_ = fractions.gcd(a, b)
L = prime_factorize(gcd_)
print(len(list(set(L)))+1)

Submission status: Accepted

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

for i in range(1,int(gcd**0.5)+1): 
    if gcd% i == 0: 
        lista.append(i)
        if i!=int(gcd/i):
            lista.append(int(gcd/i))

#print(lista)
lista=lista[1:]
lista.sort()
listb=[]
for i in range(len(lista)):
    flag = True
    for j in range(len(listb)):
        if lista[i]%listb[j]==0:
            flag = False    
    if flag==True:
        listb.append(lista[i])

print(len(listb)+1)

Submission status: Accepted

Solution code:
#from math import gcd
from fractions import gcd

A,B = map(int,input().split())
C = gcd(A,B)
def factorize(n):
    b = 2
    fct = set()
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.add(b)
        b = b + 1
    if n > 1:
        fct.add(b)
    return fct

tmp = factorize(C)
print(len(tmp)+1)

Submission status: Accepted

Solution code:
import fractions
import copy

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

def calc_divisore(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

la=calc_divisore(a)
lb=calc_divisore(b)
ll=sorted(list(set(la)&set(lb)))
ansl=[1]
ll_c=copy.copy(ll)
for i in ll_c:
    len_s=len(ll)
    ll=list(filter(lambda x: fractions.gcd(i,x)==1, ll))
    if len(ll)!=len_s:
        ansl.append(i)
print(len(ansl))

Submission status: Accepted

Solution code:
import numpy as np
def p(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 = np.min([A, B])
a = p(A)
b = p(B)
t = set(a) & set(b)
print(len(t) + 1)

Submission status: Accepted

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

def cf(x1,x2):
    cf=[]
    n =max(x1,x2)
    m=min(x1,x2)
    for i in range(1,int(m**0.5)+1):
        if m % i == 0:
          if n % i == 0:
            cf.append(i)
          if i != m//i and n % (m//i) == 0:
            cf.append(m//i)
    return cf

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

tmp=cf(a,b)
sum=0
y=[]
for k in tmp:
  if is_prime(k):
    sum += 1

print(sum)

Submission status: Accepted

Solution code:
import fractions
a,b = map(int,input().split())
b = fractions.gcd(a,b)
c = 0
a = 0
for i in range(2,1000001):
    while b%i == 0:
        b //= i
        a = 1
    if a:
        c+=1
    a = 0
    if b == 1:
        break
if b != 1:
    c += 1
print(c+1)

Submission status: Accepted

Solution code:
from fractions import gcd
import math
a,b=map(int,input().split())
g=gcd(a,b)
ans=1
for i in range(2,math.floor(g**.5)+1):
  if g%i==0:
    ans+=1
    while g%i==0:
      g//=i
if g!=1:
  ans+=1
print(ans)

Submission status: Accepted

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


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

    return divisors

import math

def is_prime(n):
    if n == 1: return True

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

import fractions
x = fractions.gcd(A, B)
divisors = make_divisors(x)
ans = 0
for d in divisors:
    if is_prime(d):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import collections
A,B=map(int,input().split())
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,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(list(collections.Counter(prime_factorize(gcd(A,B))).keys()))+1)

Submission status: Accepted

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

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

    return arr

print(len(set(factorization(A)) & set(factorization(B)))+1)

Submission status: Accepted

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

def getPrimeFactors(x):
    ans = []
    for d in range(2, int(x**0.5)+1):
        while x%d == 0:
            ans.append(d)
            x //= d
    if x != 1:
        ans.append(x)
    return ans

res_a = getPrimeFactors(a)
res_b = getPrimeFactors(b)

res = len(set(res_a) & set(res_b))
print(res + 1)

Submission status: Accepted

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

temp = 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

d = make_divisors(temp)
d.sort()

for ele in d:
    if ele==1:
        continue
    d = [e for e in d if e%ele!=0 or ele==e] 

print(len(d))

Submission status: Accepted

Solution code:
import math
def div(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
def is_primeplus(n):
    if n == 1:
        return 1
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return 0
    return 1
a,b = map(int,input().split())
c = list(set(div(a)) & set(div(b)))
ans = 0
for i in range(len(c)):
    if is_primeplus(c[i]):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
s=list(map(int,input().split()))
c=0
def gcd(x,y):
  if y==0: 
    return x
  else:
    return gcd(y,x%y)
a=max(s)
b=min(s)
pri=[]
pri.append(1)
def primary(n):
    b = 2
    while b * b <= n:
        while n % b == 0:
            n //= b
            pri.append(b)
        b = b + 1
    if n > 1:
        pri.append(n)
    return
primary(gcd(a,b))
pp=0
for j in range(len(pri)-1):
  if pri[j]==pri[j+1]:
    pp+=1
print(len(pri)-pp)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

# from math import gcd
from fractions import gcd

def isprime(x :int):
    if(x == 1):
        return False

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

    return True


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 solve(A: int, B: int):

    x = list(set(make_divisors(A)) & set(make_divisors(B)))
    
    ans = 1
    for i in x:
        if(isprime(i)):
            ans += 1

    print(ans)
            
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

divisors = []

minAB = min(A,B)
maxAB = max(A,B)
upper = int(math.sqrt(minAB+1) + 1)
ans = 1

for i in range(1, upper):
    if minAB % i == 0:
        divisors.append(i)
        if i != minAB//i:
            divisors.append(minAB//i)

divisors.sort()
#print(divisors)

flag = [True] * len(divisors)
for i, num in enumerate(divisors):
    if maxAB % num != 0:
        flag[i] = False
        continue
    for x in divisors:
        if x == 1 :
            continue
        if x > math.sqrt(num):
            break
        if num % x ==0:
            flag[i] = False
            break

print(flag.count(True))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            yield i

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

def cf(x1,x2):
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            yield i

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

def prime_factorize(n):
    a = set()
    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
    if n != 1:
        a.add(n)
    return a


def solve(A: int, B: int):
    AP = prime_factorize(A)
    BP = prime_factorize(B)
    print(len(AP & BP) + 1)

    return



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions as m

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

lcd = []
cd = m.gcd(a, b)

while cd % 2 == 0:
    lcd.append(2)
    cd //= 2

f = 3
while f * f <= cd:
    if cd % f == 0:
        lcd.append(f)
        cd //= f
    else:
        f += 2
if cd != 1:
    lcd.append(cd)

lcd.append(1)

lcd = list(set(lcd))

print(len(lcd))

Submission status: Accepted

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

ans = 1
tmp = make_divisors(fractions.gcd(A ,B))
for x in tmp:
    if is_prime(x):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import fractions

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

def prime(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 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

arr = list(set(prime(a)) & set(prime(b)))
print(1+ len(arr))

Submission status: Accepted

Solution code:
#-------------------------------------------------------------------
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
    return divisors
#-------------------------------------------------------------------
import random
def is_prime(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False
 
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1
 
    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)
 
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1
 
        if y != n - 1 and t & 1 == 0:
            return False
 
    return True

#-------------------------------------------------------------------
#Python -3.4.x
from fractions import gcd
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
a,b = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

g=gcd(a,b)
#p('g ', g)
L=make_divisors(g)

#p( gcd(a,b) )
#p( L )

ans=1
for l in L:
	#if a%l==0 and b%l==0: ans+=1
	if is_prime(l): ans+=1

print(ans)

Submission status: Accepted

Solution code:

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

C = gcd(A,B)
E = make_divisors(C)
E.sort()

ans = 0
idx = 1
while C>1 and idx < len(E):
    if C%E[idx] == 0:
        ans += 1
        while C%E[idx] == 0:
            C //= E[idx]
    idx += 1
print(ans+1)

Submission status: Accepted

Solution code:
import sys
import math
if sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd


def miller_rabin(n):
    """ primality Test
        if n < 3,825,123,056,546,413,051, it is enough to test
        a = 2, 3, 5, 7, 11, 13, 17, 19, and 23.
        Complexity: O(log^3 n)
    """
    assert(n >= 1)
    if n == 2:
        return True
    if n <= 1 or not n & 1:
        return False

    primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]

    d = n - 1
    s = 0
    while not d & 1:
        d >>= 1
        s += 1

    for prime in primes:
        if prime >= n:
            continue
        x = pow(prime, d, n)
        if x == 1:
            continue
        for r in range(s):
            if x == n - 1:
                break
            if r + 1 == s:
                return False
            x = x * x % n
    return True


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

divisors = []
for i in range(1, int(pow(ab_gcd, 0.5) + 1e-6) + 1):
    if ab_gcd % i == 0:
        divisors.append(i)
        divisors.append(ab_gcd // i)

print(sum(miller_rabin(x) for x in divisors) + 1)

Submission status: Accepted

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

factor = [1]
max_iter = int(math.sqrt(greatest)) + 1
for i in range(2, max_iter):
    while greatest % i == 0:
        greatest //= i
        factor.append(i)
if greatest != 1:
    factor.append(greatest)
factor = set(factor)
print(len(factor))

Submission status: Accepted

Solution code:
s=set
def f(n):
 a=2;t=[]
 while a*a<=n:
  while n%a==0:
   n//=a;t.append(a)
  a+=1
 if n>1:
  t.append(n)
 return t
a,b=map(int,input().split())
print(len(s(f(a))&s(f(b)))+1)

Submission status: Accepted

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

ans = 1
i = 2
while i ** 2 <= f:
    if f % i == 0:
        ans += 1
    while f % i == 0:
        f = f//i
    i += 1

ans +=(f>1)
print(ans)

Submission status: Accepted

Solution code:
import math
 
def gcd(x, y):
	while y != 0:
		z = x % y
		x = y
		y = z
	return x
 
a, b = map(int, input().split())
x    = gcd(a, b)
y    = int(math.sqrt(x))
c    = 1

for i in range(2, y + 1):
	if y < i:
		break;
	if x % i == 0:
		c += 1
		while x % i == 0:
			x //= i
			
if 1 < x:
	c += 1

print(c)

Submission status: Accepted

Solution code:
a, b = [int(elem) for elem in 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

a_lst = factorize(a)
b_lst = factorize(b)
res = list(set(a_lst) & set(b_lst))
print(len(res) + 1)

Submission status: Accepted

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

from collections import Counter
def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d

facts = factorize(g)
print(len(facts) + 1)

Submission status: Accepted

Solution code:
def primeFactor(N):
    i = 2
    ret = {}
    n = N
    mrFlg = 0
    while i**2 <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
            ret[i] = k
        i += 1
        if i == 101 and n >= (2**20):
            def findFactorRho(N):
                def gcd(a, b):
                    while b: a, b = b, a % b
                    return abs(a)
                def f(x, c):
                    return ((x ** 2) + c) % N
                semi = [N]
                for c in range(1, 99):
                    x, y, d = 2, 2, 1
                    while d == 1:
                        x = f(x, c)
                        y = f(f(y, c), c)
                        d = gcd(abs(x-y), N)
                    if d != N:
                        if isPrimeMR(d): return d
                        elif isPrimeMR(N//d):
                            return N//d
                        else:
                            semi.append(d)
            while True:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                    break
                else:
                    mrFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                        ret[j] = k
                if n == 1: break

    if n > 1: ret[n] = 1
    if mrFlg > 0:
        def dict_sort(X):
            Y={}
            for x in sorted(X.keys()):
                Y[x] = X[x]
            return Y
        ret = dict_sort(ret)
    return ret

def isPrimeMR(n):
    if n == 2:
        return True
    if n == 1 or n & 1 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for a in [2, 3, 5, 7, 11, 13, 17, 19, 23]:
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False
        return True

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

A, B = map(int, input().split())
N = gcd(A, B)
pf = primeFactor(N)

print(len(pf)+1)

Submission status: Accepted

Solution code:
from fractions import gcd
 
d = gcd(*map(int, input().split()))
r = 1
i = 2
while i * i <= d:
    f = False
    while d % i == 0:
        f = True
        d //= i
    if f: r += 1
    i += 1
print(r + (d > 1))

Submission status: Accepted

Solution code:
import fractions
import collections

def p(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())
f=fractions.gcd(a,b)
c=collections.Counter(p(f))
print(len(list(c.keys()))+1)