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: Runtime Error

Solution code:
# 引用：https://qiita.com/snow67675476/items/e87ddb9285e27ea555f8
def get_fact(n):
    arr = []
    a_append = arr.append
    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
            a_append([i, cnt])

    if temp != 1:
        a_append([temp, 1])

    if not arr:
        a_append([n, 1])

    return arr


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

# check
# 参考：https://drken1215.hatenablog.com/entry/2019/10/03/175800
# ①最大公約数の素因数分解を求める
g = gcd(A, B)
fact = [f[0] for f in get_fact(g)]

# ②指数を省き、カウントする
elem = [1]
e_append = elem.append
for f in fact:
    if f not in elem:
        e_append(f)

print(len(elem))

Submission status: Runtime Error

Solution code:
from math import gcd


def get_fact(n):
    arr = []
    a_append = arr.append
    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
            a_append([i, cnt])

    if temp != 1:
        a_append([temp, 1])

    if not arr:
        a_append([n, 1])

    return arr


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

# check

# ①最大公約数の素因数分解を求める
g = gcd(A, B)
fact = [f[0] for f in get_fact(g)]

# ②指数を省き、カウントする
elem = [1]
e_append = elem.append
for f in fact:
    if f not in elem:
        e_append(f)

print(elem)

print(len(elem))

Submission status: Runtime Error

Solution code:
# D - Disjoint Set of Common Divisors

import math

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

primes = []
i = 2
while i * i <= C:
    while C % i == 0:
        C //= i
        primes.append(i)
    i += 1
if C > 1:
    primes.append(C)

print(len(set(primes)) + 1)

Submission status: Runtime Error

Solution code:
from math import gcd
A, B = map(int, input().split())
max_range = int(max(A, B)**0.5)

kouyaku = [0 for _ in range(max_range+1)]
kouyaku[1] = 1


saidai_kouyaku = gcd(A,B)
print(saidai_kouyaku)
for i in range(2,max_range):
    while saidai_kouyaku%i==0:
        kouyaku[i]+=1
        saidai_kouyaku = saidai_kouyaku/i
sum_num = sum(kouyaku)
answer = 0

for i in range(len(kouyaku)):
    if kouyaku[i] > 0:
        answer += 1
print(answer)

Submission status: Runtime Error

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

GCD = math.gcd(A, B)



import collections


def primes_ordered_dict(n):
    #
    prime_list = []
    non_prime_list = []
    number_dict = collections.OrderedDict(
        ((i, None) for i in range(n + 1)))
    #
    del number_dict[0]
    del number_dict[1]
    while True:
        # get prime
        prime, _ = number_dict.popitem(False)
        if A % prime == 0 and B % prime == 0:
            prime_list.append(prime)
        # break
        if not (prime * prime <= n):
            break
        # get non primes
        non_prime_list.append(prime * prime)
        for k in number_dict:
            if prime * k <= n:
                non_prime_list.append(prime * k)
            else:
                break
        # delete non primes
        for non_prime in non_prime_list:
            del number_dict[non_prime]
        non_prime_list.clear()

    # add rest of numbers as prime
    prime_list.extend(
        [prime for prime, _ in number_dict.items() if A % prime == 0 and B % prime == 0])

    return prime_list

if GCD == 1:
    print(1)
else:
    print(len(primes_ordered_dict(GCD))+1)

Submission status: Runtime Error

Solution code:
"""
マスターオブ整数
公約数の問題
公約数とは最大公約数の約数であるという性質がある
"""
import math
A, B = map(int, input().split())

# まず公約数を列挙したくなる
# 最大公約数を求めてその約数を列挙する
# 最大公約数はユークリッドの互除法で求めることができる

ans = 1
gcd_value = math.gcd(A, B)
for i in range(2, gcd_value + 1):
    if gcd_value == 1:
        break
    if gcd_value % i == 0:
        ans += 1
        while gcd_value % i == 0:
            gcd_value //= i

# divisorリストの中からどの二つ互いに素となるようにいくつか選ぶ
# 素因数の数+1を答えれば良い

print(ans)

Submission status: Runtime Error

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

GCD = math.gcd(A, B)



def primes_dict(n):
    #
    prime_list = []
    non_prime_list = []
    k_list = []
    number_dict = {
        i: None for i in reversed(range(n + 1))}
    #
    del number_dict[0]
    del number_dict[1]
    while True:
        # get prime
        prime, _ = number_dict.popitem()
        if A % prime == 0 and B % prime == 0:
            prime_list.append(prime)
        if prime * prime > n:
            break

        # get non primes
        non_prime_list.append(prime * prime)
        while True:
            k, _ = number_dict.popitem()
            k_list.append(k)
            if prime * k > n:
                break
            non_prime_list.append(prime * k)

        while k_list:
            number_dict[k_list.pop()] = None

        # delete non prime
        while non_prime_list:
            del number_dict[non_prime_list.pop()]

    while number_dict:
        prime, _ = number_dict.popitem()
        if A % prime == 0 and B % prime == 0:
            prime_list.append(prime)

    return prime_list

if GCD == 1:
    print(1)
else:
    print(len(primes_dict(GCD))+1)

Submission status: Runtime Error

Solution code:
import collections as col
import math

def prime(n):
    ans = []
    num = n
    for i in range(2,int(n**0.5)+1):
        if i%2==0 and i!=2: continue
        while num%i == 0: num //= i ; ans.append(i)
    if num != 1: ans.append(num)
    return ans

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

a,b = map(int,input().split())
primes = prime(math.gcd(a,b))
cnt = col.Counter(primes)
ans = len(cnt) + 1
print(ans)

Submission status: Runtime Error

Solution code:
import collections as col
import math as ma

def prime(n):
    ans = []
    num = n
    for i in range(2,int(n**0.5)+1):
        if i%2==0 and i!=2: continue
        while num%i == 0: num //= i ; ans.append(i)
    if num != 1: ans.append(num)
    return ans

a,b = map(int,input().split())
gcd = ma.gcd(a,b)
primes = prime(gcd)
cnt = col.Counter(primes)
ans = len(cnt) + 1
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

def common_divisors(x, y, reverse=False):
    return divisors(gcd(x, y), reverse=reverse)

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

d = common_divisors(a, b)
MAX_VAL = d[-1]
prime = [1] * (MAX_VAL+1)
prime[0] = prime[1] = 0
for i in range(2, int(MAX_VAL**0.5)+1):
    if prime[i]:
        for k in range(2*i, MAX_VAL+1, i):
            prime[k] = 0

print(len([i for i in d if i == 1 or prime[i]]))

Submission status: Runtime Error

Solution code:
#include "stdc++.h"
using namespace std;

//a<=b 最大公約数
int gcd(int a, int b) {
	if (b % a == 0) {
		return a;
	}
	return gcd(b % a, a);
}
//b=2 素因数分解
vector<int> fa(int a, int b) {
	vector<int> lst;
	while (1) {
		if (b * b > a) {
			lst.push_back(a);
			break;
		}
		if (a % b == 0) {
			lst.push_back(b);
			b = b;
			a = a / b;
			continue;
		}
		b = b++;
	}
	return lst;
}

int main() {
	int a, b;
	cin >> a >> b;
	vector<int> lst = fa(gcd(min(a, b), max(a, b)), 2);
	int in = 2;
	int x = lst.at(0);
	for (int i = 0; i < lst.size(); i++) {
		if (x != lst.at(i)) {
			in = in++;
		}
		x = lst.at(i);
	}
	if (lst.at(0) == 1) {
		cout << 1 << endl;
	}
	else {
		cout << in << endl;
	}
}

Submission status: Runtime Error

Solution code:
def M(a,b,n):#最大公約数(n=2)
    if n*n>a and n*n>b:
        return 1
    while 1:
        if a%n==b%n==0:
            a=a/n
            b=b/n
            break
        if n*n>a and n*n>b:
            return 1
        n=n+1
    return n*M(a,b,n)

def S(o,n):#素因数分解(n=2)
    if o%n!=0:
        return S(o,n+1)
    o=int(o/n)
    return n

def SS(o):
    y=[S(o,2)]
    while 1:
        n=y[-1]
        o=int(o/n)
        if o==1:
            break
        if n*n>o:
            y.append(o)
            break
        y.append(S(o,n))
    return y

a,b=map(int,input().split())
o=M(a,b,2)
y=SS(o)
if y==[1]:
    print(1)
else:
    x=y[0]
    A=0
    for i in y:
        if x!=i:
            A=A+1
        x=i
    print(A+2)

Submission status: Runtime Error

Solution code:
import sys
from math import sqrt
from fractions import gcd

A, B = map(int, input().split())
loop = gcd(A, B)
ans = 1

if loop <= 3:
    for i in range(2, loop + 1):
        if A % p == 0 and B % p == 0:
            ans += 1 
    print(ans)
    sys.exit()

def eratosthenes(n):
    if n <= 1:
        return []
    prime = [2]
    lim = int(sqrt(n))
    num = list(range(3, n, 2))

    while lim > num[0]:
        prime.append(num[0])
        num = [i for i in num if i % num[0] != 0]
    
    return prime + num

for p in eratosthenes(loop):
    if A % p == 0 and B % p == 0:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
from math import sqrt
from fractions import gcd

A, B = map(int, input().split())
loop = gcd(A, B)
ans = 1

if loop == 1:
    print(1)
    sys.exit()

def eratosthenes(n):
    if n <= 1:
        return []
    prime = [2]
    lim = int(sqrt(n))
    num = list(range(3, n, 2))

    while lim > num[0]:
        prime.append(num[0])
        num = [i for i in num if i % num[0] != 0]
    
    return prime + num

for p in eratosthenes(loop):
    if A % p == 0 and B % p == 0:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
from math import sqrt
from fractions import gcd

A, B = map(int, input().split())
loop = gcd(A, B)
ans = 1

def eratosthenes(n):
    if n <= 1:
        return []
    prime = [2]
    lim = int(sqrt(n))
    num = list(range(3, n, 2))

    while lim > num[0]:
        prime.append(num[0])
        num = [i for i in num if i % num[0] != 0]
    
    return prime + num

for p in eratosthenes(loop):
    if A % p == 0 and B % p == 0:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
def M(a,b,n):#最大公約数(n=2)
    if n*n>a and n*n>b:
        return 1
    while 1:
        if a%n==b%n==0:
            a=a/n
            b=b/n
            break
        if n*n>a and n*n>b:
            return 1
        n=n+1
    return n*M(a,b,n)

def S(o,n):#素因数分解(n=2)
    y=[]
    if o==1:
        return 1
    while 1:
        if o%n==0:
            o=o/n
            y.append(int(n))
            continue
        if n*n>o:
            y.append(int(o))
            break
        n=n+1
    return y

a,b=map(int,input().split())
o=M(a,b,2)
y=S(o,2)
x=y[0]
A=0
if len(y)>1:
    if y[-1]<y[-2]:
        y.pop()
for i in y:
    if i!=x:
        A=A+1
    a=i
print(A+2)

Submission status: Runtime Error

Solution code:
import math

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

maxn=10**6
prime=[1]*(maxn+1)
prime[0]=0
prime[1]=0

for i in range(2,maxn+1):
    if prime[i]==0:
        continue

    for j in range(2,maxn//i+1):
        prime[i*j]=0

C=math.gcd(A,B)
cnt=1

for i in range(2,maxn+1):
    if prime[i]==0:
        continue

    if C%i==0:
        while C%i==0:
            C//=i
        cnt+=1

if C>1:
    cnt+=1

print(cnt)

Submission status: Runtime Error

Solution code:
import math

def test(a,b):
  num = 2
  x = math.gcd(a,b)
  s = []
  while x != 1:
    if(x % num == 0):
      x = x / num
      s.append(num)
    else:
      num += 1

  return set(s)

def main():

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

  num = []

  num = list(test(a, b))
  num.append(1)
  print(len(num))

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import math
def IS_sosu(n):
    for i in range(2, math.ceil(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True
A, B = map(int, input().split())
gcd = math.gcd(A, B)
if gcd == 1:
    print(1)
elif IS_sosu(gcd):
    print(2)
else:
    ans = 1
    end = x
    for i in range(2, end + 1):
        if x % i == 0:
            x = x // i
            ans += 1
            while x % i == 0:
                x = x // i
            if x == 1 :
                break
    print(ans)

Submission status: Runtime Error

Solution code:
import math
#素数判定プログラム
def IS_sosu(n):
    for i in range(2, int(n ** (1/2)) + 1):
        if n % i == 0:
            return False
    return True

#実装
A, B = map(int, input().split())
gcd = math.gcd(A, B)
if gcd == 1:
    print(1)
elif IS_sosu(gcd):
    print(2)
else:
    ans = 1
    end = x
    for i in range(2, end + 1):
        if x % i == 0:
            x = x // i
            ans += 1
            while x % i == 0:
                x = x // i
            if x == 1 :
                break
    print(ans)

Submission status: Runtime Error

Solution code:
import math
#素数判定プログラム
def IS_sosu(n):
    for i in range(2, math.floor(n ** (1/2)) + 1):
        if n % i == 0:
            return False
    return True

#実装
A, B = map(int, input().split())
gcd = math.gcd(A, B)
if gcd == 1:
    print(1)
elif IS_sosu(gcd):
    print(2)
else:
    ans = 1
    end = x
    for i in range(2, end + 1):
        if x % i == 0:
            x = x // i
            ans += 1
            while x % i == 0:
                x = x // i
            if x == 1 :
                break
    print(ans)

Submission status: Runtime Error

Solution code:
import math
#素数判定プログラム
def is_sosu(n):
    for i in range(2, math.floor(n ** (1/2)) + 1):
        if n % i == 0:
            return False
    return True

#素因数分解プログラム
def bunkai(x):
    ans = 1
    end = x
    for i in range(2, end + 1):
        if x % i == 0:
            x = x // i
            ans += 1
            while x % i == 0:
                x = x // i
            if x == 1 :
                break
    return ans

#実装
A, B = map(int, input().split())
gcd = math.gcd(A, B)
if gcd == 1:
    print(1)
elif is_sosu(gcd):
    print(2)
else:
    print(bunkai(gcd))

Submission status: Runtime Error

Solution code:
import math
#素数判定プログラム
def is_sosu(n):
    for i in range(2, math.floor(n ** (1/2)) + 1):
        if n % i == 0:
            return False
    return True

#素因数分解プログラム
def bunkai(x):
    ans = 1
    end = x
    for i in range(2, end + 1):
        if x % i == 0:
            x = x // i
            ans += 1
            while x % i == 0:
                x = x // i
            if x == 1 :
                break
    return ans

#実装
A, B = map(int, input().split())
gcd = math.gcd(A, B)
print(gcd)
if gcd == 1:
    print(1)
elif is_sosu(gcd):
    print(2)
else:
    print(bunkai(gcd))

Submission status: Runtime Error

Solution code:
import math
#素数判定プログラム
def is_sosu(n):
    for i in range(2, math.floor(n ** (1/2)) + 1):
        if n % i == 0:
            return False
    return True

#素因数分解プログラム
def bunkai(x):
    ans = 1
    end = x
    for i in range(2, end + 1):
        if x % i == 0:
            x = x // i
            ans += 1
            while x % i == 0:
                x = x // i
            if x == 1 :
                break
            else:
                end = x
    return ans

#実装
A, B = map(int, input().split())
gcd = math.gcd(A, B)
if gcd == 1:
    print(1)
elif is_sosu(gcd):
    print(2)
else:
    print(bunkai(gcd))

Submission status: Runtime Error

Solution code:
mport math
#素数判定プログラム
def is_sosu(n):
    for i in range(2, math.floor(n ** (1/2)) + 1):
        if n % i == 0:
            return False
    return True

#素因数分解プログラム
def bunkai(x):
    ans = 1
    end = x
    for i in range(2, end + 1):
        if x % i == 0:
            x = x // i
            ans += 1
            while x % i == 0:
                x = x // i
            if x == 1 :
                break
            else:
                end = x
    return ans

#実装
A, B = map(int, input().split())
gcd = math.gcd(A, B)
if gcd == 1:
    print(1)
elif is_sosu(gcd):
    print(2)
else:
    print(bunkai(gcd))

Submission status: Runtime Error

Solution code:
import math
import fractions
def primefactor(a):
    s=[]
    s.append(1)
    f=0
    while a%2==0:
        f=f+1
        a=a//2
    if f>0:
        s.append(2)
    for i in range(3,int(math.sqrt(a)+1),2):
        if a%i==0:
            s.append(i)
            a=a//i
    if a>2:
        s.append(a)
    return len(s)  

a,b=sorted(map(int,input().split()))
m=math.gcd(a,b)
print(primefactor(m))

Submission status: Runtime Error

Solution code:
from math import gcd

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

n = gcd(N, M)
# print(n)

if n == 1:
    print(1)
else:
    ans = 1

    
    for i in range(2, int(gcd(N, M)**0.5)+1):
        flag = 0
        # print("i", i)
        # print("n", n)
        if n%i == 0:
            while n%i == 0:
                n //= i
                # print(n)
            flag = 1
        # print("n", n)
        ans += flag

    print(ans if n == 1 else ans+1)

Submission status: Runtime Error

Solution code:
from collections import gcd

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

n = gcd(N, M)
# print(n)
ans = 1

for i in range(2, int(n**(1/2))+2):
    flag = 0
    # print("i", i)
    while True:
        if n%i == 0:
            n //= i
            # print(n)
            flag = 1
        else:
            break
    ans += flag

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


a, b = Is()

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

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

    return arr


g = gcd(a, b)
A = factorization(g)
print(len(A)+1)

Submission status: Runtime Error

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

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

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

def solve():
    a, b = map(int, input().split())
    ans = 0
    for i in trial_division(fractions.gcd(a, b)):
        if is_prime(i):
            ans += 1
    print(ans+1)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import math

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

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

gcdAB = math.gcd(A, B)
pf = prime_factorize(gcdAB)

print(len(pf)+1)

Submission status: Runtime Error

Solution code:
import sys
import math
from math import gcd

input = sys.stdin.readline

def prime(n):
    primes = {}
    bound = int(math.sqrt(n)) + 1
    for i in range(2, bound):
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                n //= i
                if not i in primes.keys():
                    primes[i] = 1
                else:
                    primes[i] += 1
    if n != 1:
        if not n in primes.keys():
            primes[n] = 1
        else:
            primes[n] += 1
    return primes

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

Submission status: Runtime Error

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

def prime_factorize(N):
    res = []
    for i in range(2, int(math.sqrt(N)) + 1):
        if N % i != 0:
            continue

        num = 0
        while N % i == 0:
            N //= i
            num += 1
        
        res.append([i, num])

    if N != 1:
        res.append([N, 1])

    return res

A, B = LI()

g = math.gcd(A, B)
pf = prime_factorize(g)

print(len(pf) + 1)

Submission status: Runtime Error

Solution code:
import fractions
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    a, b = map(int, input().split())
    m = fractions.gcd(a, b)

    # cf. https://qiita.com/suecharo/items/14137fb74c26e2388f1f

    def make_prime_list_2(num):
        if num < 2:
            return []

        # 0のものは素数じゃないとする
        prime_list = [i for i in range(num + 1)]
        prime_list[1] = 0  # 1は素数ではない
        num_sqrt = math.sqrt(num)

        for prime in prime_list:
            if prime == 0:
                continue
            if prime > num_sqrt:
                break

            for non_prime in range(2 * prime, num, prime):
                prime_list[non_prime] = 0

        return [prime for prime in prime_list if prime != 0]

    def prime_factorization_2(num):
        """numの素因数分解
        素因数をkeyに乗数をvalueに格納した辞書型dict_counterを返す"""

        if num <= 1:
            # 例えば1を食ったときの対処の仕方は問題によって違うと思うのでそのつど考える。
            # cf. https://atcoder.jp/contests/abc110/submissions/12688244
            return False
        else:
            num_sqrt = math.floor(math.sqrt(num))
            prime_list = make_prime_list_2(num_sqrt)
            dict_counter={}
            # 何度もこの関数を呼び出して辞書を更新したい時はこれを引数にして
            # cf. https://atcoder.jp/contests/arc034/submissions/12251452

            for prime in prime_list:
                while num % prime == 0:
                    if prime in dict_counter:
                        dict_counter[prime] += 1
                    else:
                        dict_counter[prime] = 1
                    num //= prime
            if num != 1:
                if num in dict_counter:
                    dict_counter[num] += 1
                else:
                    dict_counter[num] = 1

            return dict_counter
    if m==1:
        print(1)
    else:
        d=prime_factorization_2(m)
        print(len(d)+1)


resolve()

Submission status: Runtime Error

Solution code:
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    a, b = map(int, input().split())
    m = math.gcd(a, b)

    # cf. https://qiita.com/suecharo/items/14137fb74c26e2388f1f

    def make_prime_list_2(num):
        if num < 2:
            return []

        # 0のものは素数じゃないとする
        prime_list = [i for i in range(num + 1)]
        prime_list[1] = 0  # 1は素数ではない
        num_sqrt = math.sqrt(num)

        for prime in prime_list:
            if prime == 0:
                continue
            if prime > num_sqrt:
                break

            for non_prime in range(2 * prime, num, prime):
                prime_list[non_prime] = 0

        return [prime for prime in prime_list if prime != 0]

    def prime_factorization_2(num):
        """numの素因数分解
        素因数をkeyに乗数をvalueに格納した辞書型dict_counterを返す"""

        if num <= 1:
            # 例えば1を食ったときの対処の仕方は問題によって違うと思うのでそのつど考える。
            # cf. https://atcoder.jp/contests/abc110/submissions/12688244
            return False
        else:
            num_sqrt = math.floor(math.sqrt(num))
            prime_list = make_prime_list_2(num_sqrt)
            dict_counter={}
            # 何度もこの関数を呼び出して辞書を更新したい時はこれを引数にして
            # cf. https://atcoder.jp/contests/arc034/submissions/12251452

            for prime in prime_list:
                while num % prime == 0:
                    if prime in dict_counter:
                        dict_counter[prime] += 1
                    else:
                        dict_counter[prime] = 1
                    num //= prime
            if num != 1:
                if num in dict_counter:
                    dict_counter[num] += 1
                else:
                    dict_counter[num] = 1

            return dict_counter
    if m==1:
        print(1)
    else:
        d=prime_factorization_2(m)
        print(len(d)+1)


resolve()

Submission status: Runtime Error

Solution code:
import math
from collections import Counter
A, B = map(int, input().split())
C = math.gcd(A, B)

prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(C))+1):
  while C % i == 0:
    C /= i
    prime_count[i] += 1
if C > 1:
  prime_count[int(C)] += 1

print(len(prime_count)+1)

Submission status: Runtime Error

Solution code:
def factorization(n):
    s = set()
    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
            s.add(i)

    if temp != 1:
        s.add(temp)

    if s == {}:
        s.add(n)

    return s


A, B = map(int, input().split())
mini = min(A, B)
maxi = max(A, B)

s = factorization(mini)

res = 0
for i in s:
    if maxi % i == 0:
        res += 1

print(res + 1)
def factorization(n):
    s = set()
    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
            s.add(i)

    if temp != 1:
        s.add(temp)

    if s == {}:
        s.add(n)

    return s


A, B = map(int, input().split())
mini = min(A, B)
maxi = max(A, B)

s = factorization(mini)

res = 0
for i in s:
    if maxi % i == 0:
        res += 1

print(res + 1)

Submission status: Runtime Error

Solution code:
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 primes(n):
    ass = []
    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(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

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

A_s = set(make_divisors(A))
B_s = set(make_divisors(B))

from fractions import gcd

prime_N=set(primes(gcd(A,B)))

ans = A_s&B_s&prime_N

print(len(ans)+1)

Submission status: Runtime Error

Solution code:
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 primes(n):
    ass = []
    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(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

A,B = map(int,input().split())
A_s = set(make_divisors(A))
B_s = set(make_divisors(B))
divs = A_s&B_s

max_div = max(list(divs))
prime_N=set(primes(max_div))

ans = divs&prime_N

print(len(ans)+1)

Submission status: Runtime Error

Solution code:
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 primes(n):
    ass = []
    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(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass


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

A_s = set(make_divisors(A))
B_s = set(make_divisors(B))

divs = A_s&B_s

max_div = max(list(divs))

prime_N=set(primes(max_div))

ans = divs&prime_N
ans = list(ans)

print(len(ans)+1)