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:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


def factorize(n):
    result = {1:1}
    i = 2
    x = n
    while i*i <= x:
        if n % i != 0:
            i += 1
            continue
        num = 0
        while n % i == 0:
            num += 1
            n = n / i
        result[i] = num
        i += 1
    if int(n) != 1:
        result[int(n)] = 1
    return result


A, B = map(int, input().split())
gcd_num = gcd(A, B)
print(len(factorize(gcd_num)))

Submission status: Accepted

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

ans = 1
i = 1

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

Submission status: Accepted

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

a,b = map(int,input().split())
p = gcd(a,b)
s = {1}
for i in range(2,int(p**.5)+2):
  if p%i == 0:
    s.add(i)
    p //= i
    while p%i == 0:
      p //= i
if p > 1:
  s.add(p)
print(len(s))

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を2と3以上の奇数で順次割っていくする（下から計算したら、素数判定は不要）
# 3. 2.の結果に含まれる数の種類の数＋１が答え

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
  # リストを作成して探索範囲を先に作ってforで回す処理だと、リスト生成時の計算量やメモリ消費が多いからwhileで都度計算
  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()

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を2と3以上の奇数で順次割っていくする（下から計算したら、素数判定は不要）
# 3. 2.の結果に含まれる数の種類の数＋１が答え

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: # リストを作成して探索範囲を先に作ってforで回す処理だと、リスト生成時の計算量やメモリ消費が多いからwhileで都度計算
    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()

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を2と3以上の奇数で順次割っていくする（下から計算したら、素数判定は不要）
# 3. 2.の結果に含まれる数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を2と3以上の奇数で順次割っていくする（下から計算したら、素数判定は不要）
# 3. 2.の結果に含まれる数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を2と3以上の奇数で順次割っていくする（下から計算したら、素数判定は不要）
# 3. 2.の結果に含まれる数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を2と3以上の奇数で順次割っていくする（下から計算したら、素数判定は不要）
# 3. 2.の結果に含まれる数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を2と3以上の奇数で順次割っていくする（下から計算したら、素数判定は不要）
# 3. 2.の結果に含まれる数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を2と3以上の奇数で順次割っていくする（下から計算したら、素数判定は不要）
# 3. 2.の結果に含まれる数の種類の数＋１が答え

def main():
  a, b = sorted(list(map(int, input().split())), reverse = True) #aのほうを大きくする
  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()

Submission status: Accepted

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

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)

Submission status: Accepted

Solution code:
from collections import defaultdict


def gcd(a, b):
    if a > b:
        return gcd(b, a)
    # a <= b
    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)
    # add "1"
    return len(primes) + 1
    

print(main())

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素因数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素因数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素因数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素因数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素因数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素因数の種類の数＋１が答え

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

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素数＋１が答え

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

Submission status: Accepted

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

Submission status: Accepted

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

# get GCD(Gratest Common Divisor: 最大公約数)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# get divisors(公約数)
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)

# is prime(Prime Number: 素数)
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- Coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素数＋１が答え

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

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    #if not li:
    #    li.append((x, 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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC142D - Disjoint Set of Common Divisors
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, {}

    # Divide x by 2 as much as possible
    cnt = 0
    while x % 2 == 0:
        x //= 2
        cnt += 1
    if cnt > 0:
        max_prime = 2
        ret[max_prime] = cnt

    # x must be odd -> skip even numbers
    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:  # To handle the case when x is prime greater than 2
        max_prime = x
        ret[max_prime] = 1
    return ret


def main():
    # compute the number of common prime factors
    A, B = map(int, input().split())
    g = gcd(A, B)
    ans = len(prime_factorization(g).keys()) + 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC142D - Disjoint Set of Common Divisors
from fractions import gcd


# cf. AtCoder ARC067C, Euler 012
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 = {}

    # Divide x by 2 as much as possible
    cnt = 0
    while x % 2 == 0:
        x //= 2
        cnt += 1
    if cnt > 0:
        max_prime = 2
        ret[max_prime] = cnt

    # x must be odd -> skip even numbers
    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

    # To handle the case when x is prime greater than 2
    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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC142D - Disjoint Set of Common Divisors
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)  # coprime to all numbers in "groups"
    ans = len(groups) + 1
    print(ans)


if __name__ == "__main__":
    main()