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 .

Solution (Python):




def main():
  a, b = map(int, input().split())
  while b != 0: a, b = b, a % b 
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  
  if n == 1: return ans
  
  cursor = 2
  if n % cursor == 0: ans += 1
  while n % cursor == 0: n = n // cursor
  
  cursor = 3
  
  while cursor ** 2 <= n: 
    if n == 1: break
    if n % cursor == 0: ans += 1
    while n % cursor == 0: n = n // cursor
    cursor += 2
  
  if n != 1: ans += 1
    
  return ans

if __name__ == "__main__":
  main()

Solution (Python):




def main():
  a, b = map(int, input().split())
  while b != 0: a, b = b, a % b 
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  
  if n == 1: return ans
  
  cursor = 2
  if n % cursor == 0: ans += 1
  while n % cursor == 0: n = n // cursor
  
  cursor = 3
  while cursor ** 2 <= n: 
    if n == 1: break 
    if n % cursor == 0: ans += 1
    while n % cursor == 0: n = n // cursor
    cursor += 2
  
  if n != 1: ans += 1
    
  return ans

if __name__ == "__main__":
  main()

Solution (Python):




def main():
  a, b = map(int, input().split())
  while b != 0: a, b = b, a % b 
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  
  if n == 1: return ans
  
  cursor = 2
  if n % cursor == 0: ans += 1
  while n % cursor == 0: n = n // cursor
  
  cursor = 3
  while cursor ** 2 <= n:
    if n == 1: break
    if n % cursor == 0: ans += 1
    while n % cursor == 0: n = n // cursor
    cursor += 2
  
  if n != 1: ans += 1
    
  return ans

if __name__ == "__main__":
  main()

Solution (Python):




def main():
  a, b = map(int, input().split())
  while b != 0: a, b = b, a % b 
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  if n == 1: return ans
  cursor = 2
  while cursor ** 2 <= n:
    if n == 1: break
    if n % cursor == 0: ans += 1
    while n % cursor == 0: n = n // cursor
    cursor = 3 if cursor == 2 else (cursor + 2)
  if n != 1: ans += 1
  return ans

if __name__ == "__main__":
  main()

Solution (Python):




def main():
  a, b = map(int, input().split())
  while b != 0: a, b = b, a % b 
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int(n ** 0.5) + 1
  if n == 1: return ans
  two_and_odds = [2] + [x for x in range(3, max_n, 2) if x ** 2 <= n]
  for cursor in two_and_odds:
    if n == 1: break
    if n % cursor == 0: ans += 1
    while n % cursor == 0: n = n // cursor
  if n != 1: ans += 1
  return ans

if __name__ == "__main__":
  main()

Solution (Python):
from fractions import gcd
from math import sqrt


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


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

Solution (Python):




def main():
  a, b = map(int, input().split())
  while b != 0: a, b = b, a % b 
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int(n ** 0.5) + 1
  if n == 1: return ans
  two_and_odds = [2] + [x for x in range(3, max_n, 2) if x ** 2 <= n]
  for cursor in two_and_odds:
    if n % cursor == 0: ans += 1
    while n % cursor == 0: n = n // cursor
  if n != 1: ans += 1
  return ans
    
if __name__ == "__main__":
  main()

Solution (Python):




def main():
  a, b = map(int, input().split())
  while b != 0: a, b = b, a % b 
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int(n ** 0.5) + 1
  if n == 1: return ans
  for cursor in two_and_odds(max_n):
    if n % cursor == 0: ans += 1
    while n % cursor == 0: n = n // cursor
  if n != 1: ans += 1
  return ans

def two_and_odds(max_n):
  if max_n >= 2: yield 2
  for i in range(3, max_n, 2): yield i
    
if __name__ == "__main__":
  main()

Solution (Python):




def main():
  a, b = sorted(list(map(int, input().split())), reverse = True) 
  while b != 0: a, b = b, a % b 
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int(n ** 0.5) + 1
  
  if n == 1: return ans  
  for cursor in two_and_odds(max_n):
    if n % cursor == 0: ans += 1
    while n % cursor == 0: n = n // cursor
      
  if n != 1: ans += 1
  return ans

def two_and_odds(max_n):
  if max_n >= 2: yield 2
  for i in range(3, max_n, 2): yield i
    
if __name__ == "__main__":
  main()

Solution (Python):
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())
c=(prime_factorize(x))
d=(prime_factorize(y))
n = set(c) & set(d)
m=len(n)
print(m+1)

Solution (Python):
from collections import defaultdict


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


def prime_factorization(n):
    factors = defaultdict(int)
    i = 1
    n_sub = n
    while True:
        i += 1
        if i * i > n or n_sub == 1:
            break

        while n_sub % i == 0:
            n_sub = n_sub // i
            factors[i] += 1

    if n_sub != 1:
        factors[n_sub] = 1
    return factors


def main():
    a, b = map(int, input().split())
    g = gcd(a, b)
    if g == 1:
        return 1
    primes = prime_factorization(g)
    
    return len(primes) + 1
    

print(main())

Solution (Python):




def main():
  a, b = sorted(list(map(int, input().split())), reverse = True)
  while b != 0: a, b = b, a % b
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int(n ** 0.5) + 1
  is_prime = [True for x in range(max_n + 1)]
  is_prime[0], is_prime[1] = False, False
  for cursor in two_and_odds(max_n):
    if is_prime[cursor]:
      if n % cursor == 0:
        ans += 1
        while n % cursor == 0: n = n // cursor
      for i in range(cursor, max_n, cursor): is_prime[i] = False
  if n != 1: ans += 1
  return ans

def two_and_odds(max_n):
  if max_n >= 2: yield 2
  for i in range(3, max_n, 2): yield i
    
if __name__ == "__main__":
  main()

Solution (Python):




def main():
  a, b = sorted(list(map(int, input().split())), reverse = True)
  while b != 0:
    a, b = b, a % b
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int(n ** 0.5) + 1
  is_prime = [True for x in range(max_n + 1)]
  is_prime[0], is_prime[1] = False, False
  for cursor in two_and_odds(max_n):
    if is_prime[cursor]:
      if n % cursor == 0:
        ans += 1
        while n % cursor == 0:
          n = n // cursor
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    ans += 1
  return ans

def two_and_odds(max_n):
  if max_n >= 2: yield 2
  for i in range(3, max_n, 2): yield i
    
if __name__ == "__main__":
  main()

Solution (Python):




def main():
  a, b = sorted(list(map(int, input().split())), reverse = True)
  while b != 0:
    a, b = b, a % b
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int(n ** 0.5) + 1
  is_prime = [True for x in range(max_n + 1)]
  is_prime[0], is_prime[1] = False, False
  for cursor in two_and_odds(max_n):
    if is_prime[cursor]:
      if n % cursor == 0:
        ans += 1
        while n % cursor == 0:
          n = n // cursor
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    ans += 1
  return ans

def two_and_odds(max_n):
  if max_n >= 2:
  	yield 2
  for i in range(3, max_n, 2):
    yield i
    
if __name__ == "__main__":
  main()

Solution (Python):




def main():
  a, b = sorted(list(map(int, input().split())), reverse = True)
  while b != 0:
    a, b = b, a % b
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int((n ** 0.5) // 1) + 1
  is_prime = [True for x in range(max_n + 1)]
  is_prime[0], is_prime[1] = False, False
  for cursor in two_and_odds(max_n):
    if is_prime[cursor]:
      if n % cursor == 0:
        ans += 1
        while n % cursor == 0:
          n = n // cursor
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    ans += 1
  return ans

def two_and_odds(max_n):
  if max_n >= 2:
  	yield 2
  for i in range(3, max_n, 2):
    yield i
    
if __name__ == "__main__":
  main()

Solution (Python):




from fractions import gcd

def main():
  a, b = map(int, input().split())
  print(num_facto(gcd(a,b)) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int((n ** 0.5) // 1) + 1
  is_prime = [True for x in range(max_n + 1)]
  is_prime[0], is_prime[1] = False, False
  for cursor in two_and_odds(max_n):
    if is_prime[cursor]:
      if n % cursor == 0:
        ans += 1
        while n % cursor == 0:
          n = n // cursor
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    ans += 1
  return ans

def two_and_odds(max_n):
  if max_n >= 2:
  	yield 2
  for i in range(3, max_n, 2):
    yield i
    
if __name__ == "__main__":
  main()

Solution (Python):




from fractions import gcd
from math import floor

def main():
  a, b = map(int, input().split())
  print(num_facto(gcd(a,b)) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = floor(n ** 0.5) + 1
  is_prime = [True for x in range(max_n + 1)]
  
  for cursor in two_and_odds(max_n):
    if n == 1: break
    if is_prime[cursor]:
      if n % cursor == 0:
        ans += 1
        while n % cursor == 0:
          n = n // cursor
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    ans += 1
  return ans

def two_and_odds(max_n):
  yield 2
  for i in range(3, max_n, 2):
    yield i
    
if __name__ == "__main__":
  main()

Solution (Python):




from fractions import gcd
from math import floor

def main():
  a, b = map(int, input().split())
  fac = facto(gcd(a,b))
  print(len(fac))  
  
def facto(n):
  fac = [1]
  max_n = floor(n ** 0.5) + 1
  is_prime = [True for x in range(max_n + 1)]
  
  for cursor in two_and_odds(max_n):
    if n == 1: break
    if is_prime[cursor]:
      if n % cursor == 0:
        fac.append(cursor)
        while n % cursor == 0:
          n = n // cursor
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    fac.append(n)
  return fac

def two_and_odds(max_n):
  yield 2
  for i in range(3, max_n, 2):
    yield i
    
if __name__ == "__main__":
  main()

Solution (Python):
import math

class Prime:
    seeds = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

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

    def decompose(self, n):
        ps_max = self.seeds[-1]
        primes = {}
        setdef = primes.setdefault

        for p in self.seeds:
            while n % p == 0:
                setdef(p, 0)
                primes[p] += 1
                n //= p

        p = ps_max
        while p <= math.sqrt(n):
            if n % p == 0:
                setdef(p, 0)
                primes[p] += 1
                n //= p
            p += 2
        if n > 1:
          setdef(n, 1)

        return primes

prime = Prime()
 
a, b = map(int, input().split())
primes = prime.decompose(prime.gcd(a, b))
 
print(len(primes) + 1)

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


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


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


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

x = divisors(gcd(a, b))

ans = 1
for _x in x:
    ans += is_prime(_x)

print(ans)

Solution (Python):
from math import sqrt, ceil


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

A, B = map(int, input().split())
if A > B:
    A, B = B, A
g = gcd(A, B)
s = set(); s.add(1)
sqrt_g_plus = ceil(sqrt(g))+1
i = 2


while i < sqrt_g_plus:
    if g%i == 0:
        s.add(i)
        g //= i
    else:
        i += 1

if g > 1:
    s.add(g)

print(len(s))

Solution (Python):

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

gcd = my_gcd(a, b)
sqrt_gcd = int(gcd ** 0.5)
div_list = []
i = 2
res_gcd = gcd

while i <= sqrt_gcd:
  if res_gcd % i == 0:
    div_list.append(i)
    res_gcd = res_gcd / i
  else:
    i += 1
  if res_gcd == 1:
    break
if res_gcd > 1:
  div_list.append(gcd)
uni_cd = list(set(div_list))
ans = 1 + len(uni_cd)
print(ans)

Solution (Python):




import itertools
from fractions import gcd
from math import ceil

def main():
  a, b = map(int, input().split())
  fac = facto(gcd(a,b))
  print(len(fac))  
  
def facto(n):
  fac = [1]
  if n == 1:
    return [1]
  elif n % 2 == 0:
    fac = [1, 2]
    while n % 2 == 0:
      n = n // 2
  
  max_n = ceil(n ** 0.5) + 1
  
  is_prime = [True for x in range(max_n)]
  for cursor in range(3, max_n, 2):
    if is_prime[cursor]:
      if n % cursor == 0:
        fac.append(cursor)
        while n % cursor == 0:
          n = n // cursor
        if n == 1:
          break
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    fac.append(n)
  return fac

if __name__ == "__main__":
  main()

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7



from fractions import gcd

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


g = gcd(A, B)

if g == 1:
    print(1)
    exit()

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

print(len(prime_factorize(g)) +1)

Solution (Python):


import math
def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

def fact(n):
    r = [1]
    if n % 2 == 0:
        r.append(2)
        while n % 2 == 0:
            n //= 2
    i = 3
    k = int(math.sqrt(n))
    while i <= k:
        if n % i == 0:
            r.append(i)
            while n % i == 0:
                n //= i
            k = int(math.sqrt(n))
        i += 2
    if n > 1:
        r.append(n)
    return r

def main():
    A, B = map(int, input().split())
    t = gcd(A, B)
    print(len(fact(t)))


if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd

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

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

x = gcd(A, B)
prime = prime_factorize(x)

primeset = set()
for p in prime:
    primeset.add(p)

print(len(primeset)+1)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



import fractions
from functools import reduce
from collections import Counter

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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 = II()

x = gcd_list([A,B])
c = Counter(prime_factorize(x))
print(len(c.keys())+1)

Solution (Python):
import fractions, math
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, 2])
    return arr
A, B = map(int, input().split())
N = fractions.gcd(A, B)
prime_list = factorization(N)
if N == 1:
    print(1)
else:
    print(len(prime_list)+1)

Solution (Python):
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


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

g = gcd(a, b)
ret = 1
i = 2
while i * i <= g:
    if g % i == 0:
        while g % i == 0:
            g /= i
        ret += 1
    i += 1

if g > 1:
    ret += 1

print(ret)

Solution (Python):
from math import sqrt


def prime_factorization(x):
    li = []
    num = x
    for i in range(2, int(sqrt(x)) + 1):
        if num % i == 0:
            cnt = 0
            while num % i == 0:
                cnt += 1
                num //= i
            li.append((i, cnt))

    if num != 1:
        li.append((num, 1))

    
    

    return li


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

a_pf = [(1, 1)] + prime_factorization(a)
b_pf = [(1, 1)] + prime_factorization(b)

ans = 0
for ap, at in a_pf:
    for bp, bt in b_pf:
        if ap == bp:
            ans += 1

print(ans)

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

a, b = map(int, input().split())
import fractions
print(len(set(prime_decomposition(fractions.gcd(a,b))))+1)

Solution (Python):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

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

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

def main():
    """ main """
    A,B = map(int, input().split())
    print(len(factorize(gcd(A,B)))+1)

if __name__ == '__main__':
    main()

Solution (Python):
A, B = map(int, input().split())
def happa(A,B):
    if B > A:
        temp = A
        A = B
        B = temp
    if A % B == 0:
        return B
    R = A % B
    return happa(B,R)

def zero(B):
    A = []
    while B > 1:
        f = 0
        for i in range(2,int(B**(1/2)+1)):
            if B % i == 0:
                A.append(i)
                B /= i
                f = 1
                break
        if f == 0:
            A.append(int(B))
            break
    import collections
    return len(collections.Counter(A))
print(zero(happa(A,B))+1)

Solution (Python):
import math
import collections
def f(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 = n//f
        else:f += 2
    if n != 1:
        a.append(n)
    return a

a,b = map(int,input().split())
a = set(collections.Counter(f(a)).keys())
b = set(collections.Counter(f(b)).keys())
print(len(a&b)+1)

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

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

def factorize(n):
    f = []

    div = 2
    while div ** 2 <= n:
        while n % div == 0:
            f.append(div)
            n //= div
        div += 1

    if n > 1:
        f.append(n)

    return f

g = gcd(a, b)
f = factorize(g)

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

Solution (Python):
from fractions import*;n=gcd(*map(int,input().split()));a=i=1
while i*i<n:
 i+=1;a+=n%i<1
 while n%i<1:n/=i
print(a+(n>1))

Solution (Python):
import math
import collections
def f(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 = n//f
        else:f += 2
    if n != 1:
        a.append(n)
    return a

a,b = map(int,input().split())
a = set(collections.Counter(f(a)).keys())
b = set(collections.Counter(f(b)).keys())
print(len(a&b)+1)

Solution (Python):
global primeList
primeList = []

def primeFactorize(X):
  global primeList
  result = set()
  for prime in primeList:
      while X % prime == 0:
        result.add(prime)
        X //= prime
  if X != 1:
      result.add(X)
  return result

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

isPrime = [True for i in range(1000001)]
isPrime[0] = isPrime[1] = False;
primeList.append(2)
for i in range(4,1000001,2):
  isPrime[i] = False

for i in range(3,1000001,2):
    if not isPrime[i]:
      continue
    primeList.append(i)
    for j in range(i, 1000000//i + 1):
      isPrime[i*j] = False

pA = primeFactorize(A)
pB = primeFactorize(B)
print(len(pA.intersection(pB)) + 1)

Solution (Python):
from fractions import*
n=gcd(*map(int,input().split()))
a=i=1
while i*i<n:
 i+=1;a+=n%i<1
 while n%i<1:n/=i
print(a+(n>1))

Solution (Python):
from fractions import*
n=gcd(*map(int,input().split()))
a=i=1
while i*i<n:
 i+=1;a+=n%i<1
 while n%i<1:n//=i
print(a+(n>1))

Solution (Python):
from fractions import*
n=gcd(*map(int,input().split()))
a=i=1
while i*i<=n:
 i+=1;a+=n%i<1
 while n%i<1:n//=i
print(a+(n>1))

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

p = a
q = b
r = p % q
while r > 0:
  p = q
  q = r
  r = p % q
sgd = q

d = 2
count = 1
while d * d <= sgd:
  d_flag = False
  while q % d == 0:
    d_flag = True
    q //= d
  if d_flag:
    count += 1
  if d == 2:
    d = 3
  else:
    d += 2
if q > 1:
  count += 1
    
print(count)

Solution (Python):
from fractions import*
n=gcd(*map(int,input().split()))
a=i=2
while i*i<=n:
 a+=n%i<1
 while n%i<1:n//=i
 i+=1
print(a-(n<2))

Solution (Python):
from fractions import*
n=gcd(*map(int,input().split()))
a=1
i=2
while i*i<=n:
 a+=n%i<1
 while n%i<1:n//=i
 i+=1
print(a+(n>1))

Solution (Python):

def gcd(x: int, y: int) -> int:
    while y:
        x, y = y, x % y
    return x


def prime_factorization(x: int) -> dict:
    max_prime, ret = 0, {}

    
    cnt = 0
    while x % 2 == 0:
        x //= 2
        cnt += 1
    if cnt > 0:
        max_prime = 2
        ret[max_prime] = cnt

    
    cnt = 0
    for i in range(3, int(x ** 0.5) + 1, 2):
        cnt = 0
        while x % i == 0:
            x //= i
            max_prime = i
            cnt += 1
        if cnt > 0:
            ret[max_prime] = cnt

    if x > 2:  
        max_prime = x
        ret[max_prime] = 1
    return ret


def main():
    
    A, B = map(int, input().split())
    g = gcd(A, B)
    ans = len(prime_factorization(g).keys()) + 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import fractions

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


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

gcd_ = fractions.gcd(A,B)
if gcd_ == 1:
  print(1)
else:
  print(len(set(trial_division(gcd_)))+1)

Solution (Python):

from fractions import gcd



def prime_factorization(x: int) -> dict:
    """
    Prime factorization of a number (trial division)
    
    Args: x (int): a number to be resolved
    Return: ret (dict): {prime factor: power}
    
    e.g., n = 2^a * 3^b -> {2: a, 3: b}
    """
    max_prime = 0
    ret = {}

    
    cnt = 0
    while x % 2 == 0:
        x //= 2
        cnt += 1
    if cnt > 0:
        max_prime = 2
        ret[max_prime] = cnt

    
    cnt = 0
    for i in range(3, int(x ** 0.5) + 1, 2):
        cnt = 0
        while x % i == 0:
            x //= i
            max_prime = i
            cnt += 1
        if cnt > 0:
            ret[max_prime] = cnt

    
    if x > 2:
        max_prime = x
        ret[max_prime] = 1
    return ret


def main():
    A, B = map(int, input().split())
    g = gcd(A, B)
    ans = len(prime_factorization(g).keys()) + 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from fractions import gcd
n,ans,i=gcd(*map(int,input().split())),1,2
while i*i<=n:
  ans+=n%i==0
  while n%i==0:n//=i
  i+=1
print(ans+(n>1))

Solution (Python):
from math import sqrt
a, b = (int(i) for i in input().split())

GCD = lambda x, y: (GCD(y, x % y) if x % y else y)
ab_gcd = GCD(a, b)

def factoring(gcb,n=2):
    for i in range(n,int(gcb**0.5)+1):
        if gcb%i==0:
            ret = factoring(gcb//i,i)
            ret[i] = ret.get(i,0)+1
            return ret
    return {gcb:1}

result = set(factoring(ab_gcd).keys())
result.add(1)
print(len(result))

Solution (Python):

from fractions import gcd


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


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


if __name__ == "__main__":
    main()

Solution (Python):

from fractions import gcd



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


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


if __name__ == "__main__":
    main()

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

prime_A = set()
prime_B = set()

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

Solution (Python):

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


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


if __name__ == "__main__":
    main()

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

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

Solution (Python):

import sys
from fractions import gcd
from collections import Counter

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

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

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


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

    if cd == 1:
        print(1)
        return

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

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


if __name__ == "__main__":
    solve()

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

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

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

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

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

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

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

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

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

    return arr

fac = factorization(g)
fac

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

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

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

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