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 p_prime(n): 
    prime = [2]
    for i in range(3,n+1):
        flag = 0
        for j in prime:
            if i%j == 0:
                flag = 1
                break
            if i**0.5 < j:
                break
        if flag == 0:
            prime.append(i)
    return prime

import time

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

M = fractions.gcd(A,B)

a = {}
prime = p_prime(int(M**0.5+1))
for p in prime:
    count = 0
    while M%p ==0:
        count += 1
        M //= p
    if count > 0:
        a[p] = count
if M != 1:
    a[M] = 1

print(len(a)+1)

Submission status: Accepted

Solution code:
import math


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


def main():
    A, B = map(int, input().split())
    g = gcd(A, B)
    rt = int(math.sqrt(g))
    ans = set([1])
    for x in range(2, rt+1):
        if g % x == 0:
            ans.add(x)
            while g % x == 0:
                g //= x
    if g != 1:
        ans.add(g)
    print(len(ans))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    from fractions import gcd
    from collections import Counter
    a,b=map(int,input().split())
    c=len(Counter(soinsuu(gcd(a,b))))+1
    print(c)
    
def soinsuu(a):
    yy,j=[],2
    y=yy.append
    while(a>1):
        for i in range(j,int(a**0.5)+1):
            if a%i==0:
                y(i)
                a,j=a//i,i
                break
        else:
            y(a)
            break
    yy.sort()
    return yy
    
if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def prime_factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

a, b = [int(item) for item in input().split()]    
afct = set(prime_factorize(a) + [1])
bfct = set(prime_factorize(b) + [1])

ans = 0
for item in bfct:
    if item in afct:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import fractions
import collections
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

def factorize(n: int):
    """
    与えられた自然数を素因数分解する。返り値は素因数をキーに持ち指数を持つ defaultdict

    Parameters
    ----------
        n : int
            素因数分解したい整数

    Returns
    -------
        defaultdict
            素因数分解の結果。
    """
    res = collections.defaultdict(int)
    i = 2
    while i * i <= n:
        while n % i == 0:
            n //= i
            res[i] += 1
        i += 1
    if n != 1:
        res[n] += 1
    return res

def main():
    A, B = mi()
    G = fractions.gcd(A, B)
    mp = factorize(G)
    print(max(len(mp) + 1, 1))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
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(int(n))
  return table

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

    # divisors.sort()
    return divisors


a,b = m()

kkk = gcd(a,b)

kkk = prime_decomposition(kkk)

kkk = set(kkk)

print(len(kkk)+1)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np
from fractions import gcd

# 1と素数をとる

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

D = gcd(A,B)

U = 10**6 + 100
is_prime = np.zeros(U,dtype=np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(int(U**.5)+10):
    if is_prime[p]:
        is_prime[p*p::p+p] = 0
primes = is_prime.nonzero()[0]

factor = primes[D%primes==0]

for p in factor:
    while D%p == 0:
        D //= p

answer = 1+len(factor)
if D != 1:
    answer += 1
print(answer)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
def gcd(a,b):
  while b:a,b=b,a%b
  return a
c=gcd(a,b)
def divisor(n):
  ass=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      ass.append(i)
      if i!=n//i:ass.append(n//i)
  return ass
def is_prime(n):
  if n==1:return True#特例
  for i in range(2,int(n**0.5)+1):
    if n%i==0:return False
  return True
d=sorted(divisor(c))
x=0
for i in d:
  if is_prime(i):x+=1
print(x)

Submission status: Accepted

Solution code:
from fractions import gcd

def prime_factors(n):
    l=[]
    while n%2==0:
        l.append(2)
        n//=2
    while n%3==0:
        l.append(3)
        n//=3
    f=5
    limit=int(n**.5)
    while f<=limit:
        while n%f==0:
            l.append(f)
            n//=f
        f+=2
        while n%f==0:
            l.append(f)
            n//=f
        f+=4
    if n!=1:l.append(n)
    return l

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

Submission status: Accepted

Solution code:
A,B=map(int,input().split())
from fractions import gcd
g=gcd(A,B)
def prime_factorization(n):
    r={}
    for i in range(2,int(n**.5)+1):
        num=0
        while(True):
            x,y=divmod(n,i)
            if y!=0:
                break
            n=x
            num+=1
        if num>0:
            r[i]=num
    if n>1:
        r[n]=1
    return r
print(len(prime_factorization(g).keys())+1)

Submission status: Accepted

Solution code:
from fractions import gcd
A, B = map(int, input().split())
g = gcd(A, B)
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table
print(len(set(prime_decomposition(g)))+1)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

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


def factorize(n: int):
    d = Counter()
    m = 2

    while m * m <= n:
        while n % m == 0:
            n //= m
            d[m] += 1

        m += 1

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

    return d

from collections import Counter

a, b = li()

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

print(len(f) + 1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

#print(gcd(A,B))

x=gcd(A,B)

import math

L=int(math.sqrt(x))

FACT=dict()

for i in range(2,L+2):
    while x%i==0:
        FACT[i]=FACT.get(i,0)+1
        x=x//i

if x!=1:
    FACT[x]=FACT.get(x,0)+1

print(len(FACT)+1)

Submission status: Accepted

Solution code:
import collections
gcd = lambda x, y: gcd(y, x % y) if x % y else y
A, B = [int(_) for _ in input().split()]


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


print(1 + len(collections.Counter(prime_factorize(gcd(A, B)))))

Submission status: Accepted

Solution code:
from fractions import gcd
import math

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

N = gcd(A, B)

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

factor = prime(N)
print(len(factor) + 1)

Submission status: Accepted

Solution code:
def primeFactor(N):
    i, n, ret, d, sq = 2, N, {}, 2, 99
    while i <= sq:
        k = 0
        while n % i == 0: n, k, ret[i] = n//i, k+1, k+1
        if k > 0 or i == 97: sq = int(n**(1/2)+0.5)
        if i < 4: i = i * 2 - 1
        else: i, d = i+d, d^6
    if n > 1: ret[n] = 1
    return ret

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

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

print(len(pf)+1)

Submission status: Accepted

Solution code:
def gcd(a, b):
    """a, bの最大公約数(greatest common divisor:GCD)を求める"""
    if b == 0:
        return a
    return gcd(b, a%b)

def make_prime_factors2(n):
    """自然数nの素因数を列挙した圧縮済みリストを出力する
    計算量：O(sqrt(N))
    入出力例：156 -> [(2, 2), (3, 1), (13, 1)]
    """
    prime_factors = []
    for k in range(2, int(n**0.5) + 1):
        cnt = 0
        while n % k == 0:
            cnt += 1
            n = n // k
        if cnt != 0:
            prime_factors.append((k, cnt))
    if n != 1:
        prime_factors.append((n, 1))
    return prime_factors
  
a, b = map(int, input().split())
max_gcd = gcd(a, b)
li = make_prime_factors2(max_gcd)
print(len(li) + 1)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    print((n-(n>>1))/n)
    return

#B
def B():
    n,k = LI()
    h = LI()
    ans = 0
    for i in h:
        if i >= k:
            ans += 1
    print(ans)
    return

#C
def C():
    n = I()
    a = LI()
    b = [(a[i],i+1) for i in range(n)]
    b.sort()
    ans = [b[i][1] for i in range(n)]
    print(*ans)
    return

#D
def D():
    def divisor(n):
        if n < 4:
            return set([n])
        res = set([1])
        i = 2
        m = n
        while i**2 <= n:
            if m%i == 0:
                while m%i == 0:
                    m //= i
                res.add(i)
            i += 1
        res.add(m)
        return res
    a,b = LI()
    if min(a,b) == 1:
        print(1)
        return
    s = divisor(a)
    t = divisor(b)
    s &= t
    print(len(s))
    return

#E
def E():
    n,m = LI()
    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Accepted

Solution code:
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


def get_divisors(n):
    """
    n の約数をリストで返す
    :param int n:
    :rtype: list of int
    """
    ret = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


def get_factors(n):
    """
    素因数分解
    :param int n:
    :rtype: list of int
    """
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


A, B = list(map(int, sys.stdin.readline().split()))

fa = set(get_factors(A))
fb = set(get_factors(B))
ans = len(fa & fb) + 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
def prime_factorize(N): #素因数分解
    exponent = 0
    while N%2 == 0:
        exponent += 1
        N //= 2
    if exponent: factorization = [[2,exponent]]
    else: factorization = []
    i=1
    while i*i <=N:
        i += 2
        if N%i: continue
        exponent = 0
        while N%i == 0:
            exponent += 1
            N //= i
        factorization.append([i,exponent])
    if N!= 1: factorization.append([N,1])
    assert N != 0, "zero"
    return factorization
    
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 
from fractions import gcd

a,b = [int(i) for i in readline().split()]
#a = [int(i) for i in readline().split()]

g = gcd(a,b)

if g == 1:
    print(1)
else:
    l = prime_factorize(g)
    print(len(l)+1)

Submission status: Runtime Error

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

def get_prime(n):
    num = [True]*(n + 1)
    for i in range(2, int(n**0.5) + 1):
        if num[i]:
            for j in range(i*2, n + 1, i):
                num[j] = False
    ans = [i for i in range(1, n + 1) if num[i]]
    return ans

gcd = gcd(a, b)
p = get_prime(gcd)
ans = 0
for i in p:
    if gcd%i == 0:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

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

def resolve():
    readline=sys.stdin.readline

    
    a,b=map(int, readline().rstrip().split())
    memo = [0] * (10**6 + 10)
    af = factorization(a)
    bf = factorization(b)
    for x in af:
        memo[x[0]]+=1
    for x in bf:
        memo[x[0]]+=1
    print(memo.count(2)+1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

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

def resolve():
    readline=sys.stdin.readline

    
    a,b=map(int, readline().rstrip().split())
    memo = [0] * (10**6 + 1)
    af = factorization(a)
    bf = factorization(b)
    for x in af:
        memo[x[0]]+=1
    for x in bf:
        memo[x[0]]+=1
    print(memo.count(2)+1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Submission status: Runtime Error

Solution code:
A, B = map(int, input().split())
a = set(1)
b = set(1)
n = 2
while n**2 > max(A, B):
  if A%n == 0 and n**2 <= A:
    a.add(n)
    a.add(A//n)
  if B%n == 0 and n**2 <= B:
    b.add(n)
    b.add(B//n)
ab = a & b
ab = list(ab)
answer = 0
for i, n in enumerate(ab):
  prime = True
  for j, m in enumerate(ab):
    if i != j and n%m == 0:
      prime = False
      break
  if prime:
    answer += 1
print(answer)

Submission status: Runtime Error

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    a,b = i_map()

    def make_divisors(n,m):
        lower_divisors , upper_divisors = [], []
        i = 1
        while i*i <= n:
            if n % i == 0 and m % i == 0:
                lower_divisors.append(i)
                if n%(n//i)==0 and m%(n//i)==0:
                    upper_divisors.append(n//i)
            i += 1
        return lower_divisors + upper_divisors[::-1]

    l = set(make_divisors(a,b))

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

    L = set(primes(a+b))
    L.add(1)
    print(len(L&l))










if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
a,b=list(map(int ,input().split()))
m=max(a,b)
count=0
for i in range(1,m):
	y=a/i
	z=b/i
	print(y,z)
	if(y%2==0 or z%2==0):
		if(y==0  and z==0):
		    if(y%z !=0 or z%y!=0):
			    count+=1
			else:
			    count+=0
        else:
		    count+=0
	else:
		count+=0
print(int(count))

Submission status: Runtime Error

Solution code:
import sys
from collections import deque

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

List = deque()  # リストの初期化
answer = []

for i in range(1, max(min(A, B, 10 ** 6 + 1), 2)):
    if A % i == 0 and B % i == 0:
        List.append(i)

if A == B and (A in List) == False:
    List.append(A)

dp = [0] * (10 ** 6 + 1)

for n in List:

    if dp[n] != 1:
        answer.append(n)
        if n != 1:
            for i in range(1, 10 ** 6 + 1):

                if n * i < 10 ** 6 + 1:
                    dp[n * i] = 1
                else:
                    break

print(len(answer))

Submission status: Runtime Error

Solution code:
from math import *
import sympy
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
    return divisors

def eratosthenes(n):
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
                
    return prime_list
a,b = map(int,input().split())
upper = int(sqrt(min(a,b))) + 1
pl = set(eratosthenes(upper))
common_factor = make_divisors(a)&make_divisors(b)
#print(*sorted(list(common_factor)))
#common_factor = [ i for i in range(1,min(a,b)) if a % i == 0 and b % i == 0]
#print(*common_factor)
ans = 0
for i in common_factor:
    if i in pl:
        ans += 1
print(ans + 1)

Submission status: Runtime Error

Solution code:
from math import *
import sympy
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
    return divisors

def eratosthenes(n):
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
                
    return prime_list
a,b = map(int,input().split())
upper = int(sqrt(min(a,b))) + 1
pl = set(eratosthenes(upper))
common_factor = make_divisors(a)&make_divisors(b)
ans = 0
for i in common_factor:
    if i in pl:
        ans += 1
print(ans + 1)

Submission status: Runtime Error

Solution code:
from math import *
import sympy
def eratosthenes(n):
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
                
    return prime_list
a,b = map(int,input().split())
upper = int(sqrt(min(a,b))) + 1
pl = set(eratosthenes(upper))
common_factor = set(sympy.divisors(a))|set(sympy.divisors(b))
ans = 0
for i in common_factor:
    if i in pl:
        ans += 1
print(ans + 1)

Submission status: Runtime Error

Solution code:
def eratosthenes(n):
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
                
    return prime_list
a,b = map(int,input().split())
pl = set(eratosthenes(min(a,b)))
common_factor = [ i for i in range(1,min(a,b)) if a % i == 0 and b % i == 0]
ans = 0
for i in common_factor:
    if i in pl:
        ans += 1
print(ans + 1)

Submission status: Runtime Error

Solution code:
def main():
    a,b=map(lambda x: set(prime_factorize(int(x))),input().split())
    print(len(a&b)+1)

@lru_cache(maxsize=None)
def primes(n:int) -> list:
    '''n以下の全素数をlistで返す'''
    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
    return [i for i in range(n + 1) if is_prime[i]]

# 素数判定（単純な素数判定なら十分早い。大量にやる場合はX in primesがよさそう）
@lru_cache(maxsize=None)
def is_prime(n: int) -> bool:
    '''引数nが素数であればTrue、そうでなければFalseを返す'''
    if n == 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    for i in range(3, int(n**0.5)+1, 2):
        if n % i == 0:
            return False
    return True

# 素因数分解
@lru_cache(maxsize=None)
def prime_factorize(n: int) -> list:
    '''引数nの素因数分解結果のlistを返す。'''
    arr = []
    # 2で割り続け奇数まで還元する
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    # sqrt(n)までの素数で試し割
    for f in primes(int(n**0.5)):
        while n % f == 0:
            arr.append(f)
            n //= f
    if n != 1:
        arr.append(n)
    return arr

#約数リスト
def make_divisors(n: int) -> list:
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
        
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from math import gcd
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    #return pow(2, q-1, q) == 1
    return (2 ** (q - 1)) % q == 1


A, B = map(int, input().split())
l = make_divisors(gcd(A, B))
ans = 0
for num in l:
    if is_prime(num):
        ans += 1
print(ans + 1)

Submission status: Runtime Error

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

prime = []
n = max(a,b)
limit = math.sqrt(n)
data = [i+1 for i in range(1,n)]
while True:
    p = data[0]
    if limit<=p:
        prime = prime + data
        break
    prime.append(p)
    data = [e for e in data if e%p != 0]

def divisor(n):
    l = list()
    for i in prime:
        if n%i==0:
            l.append(i)
    return l

div = sorted(divisor(a) + divisor(b))
ans = 0
for i in range(len(div)-1):
    if div[i]==div[i+1]:
        ans+=1
print(ans+1)

Submission status: Runtime Error

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

prime = []
n = max(a,b)
limit = math.sqrt(n)
data = [i+1 for i in range(1,n)]
while True:
    p = data[0]
    if limit<=p:
        prime = prime + data
        break
    prime.append(p)
    data = [e for e in data if e%p != 0]

def divisor(n):
    l = list()
    for i in prime:
        if n==1:
            break
        if n%i==0:
            while n%i==0:
                n//=i
            l.append(i)
    if n!=1 or l==[]:
        l.append(n)
    return l

div = sorted(divisor(a) + divisor(b))
ans = 0
for i in range(len(div)-1):
    if div[i]==div[i+1]:
        ans+=1
print(ans+1)

Submission status: Runtime Error

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

def prime_num_check(x):
  ls = []
  ls.append(1)
  for i in range(2,x+1):
    factor = 0
    if i%2 == 0 and i != 2:
      continue
    for divisor in range(2,math.floor(math.sqrt(i))+1):
      if i%divisor == 0:
        factor += 1
    if factor == 0:
      ls.append(i)
    return ls
  
x = math.gcd(A,B)

c_divisor = prime_num_check(x)
res = len(c_divisor) * (len(c_divisor) - 1) // 2

print(res)

Submission status: Runtime Error

Solution code:
A,B=map(int,input().split())
n=max(A,B)
ans=1

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
    else:
        if A%i==0 and B%i==0:
            ans+=1
            #print(i)
            
    for j in range(i * 2, n + 1, i):
        is_prime[j] = False
        
#lis=[i for i in range(n + 1) if is_prime[i]]
print(ans)
#print(lis)

Submission status: Runtime Error

Solution code:
A,B=map(int,input().split())
n=max(A,B)
ans=1

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
    else:
        if A%i==0 and B%i==0:
            ans+=1
            #print(i)
            
    for j in range(i * 2, n + 1, i):
        is_prime[j] = False
        
lis=[i for i in range(n + 1) if is_prime[i]]
print(ans)
#print(lis)

Submission status: Runtime Error

Solution code:
A, B = cin()

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

def sieve(N):
    p = 0
    prime = []
    is_prime = [1 for _ in range(N + 1)]
    is_prime[0], is_prime[1] = 0, 0
    for i in range(2, N + 1):
        if is_prime[i]:
            p += 1
            temp = i
            prime.append(i)
            while(temp <= N):
                is_prime[temp] = 0
                temp += i
            is_prime[i] = 1
    return prime

s = sieve(int(min(A, B) ** 0.5) + 1)
s.append(1)
ans = 0
for i in s:
    if A % i == 0 and B % i == 0:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def input_li():
    return list(map(int, input().split()))


def input_int():
    return int(input())


def prime_factorization(n):
    table = []
    for x in range(2, int(n ** 0.5) + 1):
        while n % x == 0:
            table.append(x)
            n //= x
    if n > 1:
        table.append(n)
    return table


A, B = input_li()
A_LI = [x[0] for x in prime_factorization(A)]
B_LI = [x[0] for x in prime_factorization(B)]
print(len(set(A_LI) & set(B_LI)) + 1)

Submission status: Runtime Error

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    a,b = map(int,input().split())

    def make_two_divisors(a,b):
        lower_divisors,upper_divisors = [],[]
        prime_li = [True]*(max(a,b)+1)
        i = 1
        while i*i<=max(a,b):
            if prime_li[i]:
                if a%i==0 and b%i==0:
                    lower_divisors.append(i)
                    #if i != max(a,b)//i and a%(max(a,b)//i)==0 and b%(max(a,b)//i)==0:
                    #    upper_divisors.append(b//i)
                    if i!=1:
                        for j in range(i+i,max(a,b),i):
                            prime_li[j]=False 
            i+=1
        return lower_divisors
    print(len(make_two_divisors(a,b)))

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    a,b = map(int,input().split())

    def make_two_divisors(a,b):
        lower_divisors,upper_divisors = [],[]
        prime_li = [True]*(max(a,b)+1)
        i = 1
        while i*i<=max(a,b):
            if prime_li[i]:
                if a%i==0 and b%i==0:
                    lower_divisors.append(i)
                    #if i != max(a,b)//i and a%(max(a,b)//i)==0 and b%(max(a,b)//i)==0:
                    #    upper_divisors.append(b//i)
                    if i!=1:
                        for j in range(i+i,max(a,b)+1,i):
                            prime_li[j]=False 
            i+=1
        return lower_divisors
    print(len(make_two_divisors(a,b)))

if __name__=='__main__':
    main()