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: Wrong Answer

Solution code:
from fractions import gcd
import math
import numpy as np
N = list(map(int, input().split()))
g = gcd(N[0], N[1])
original_g = g
max_prime = int(np.sqrt(g))+2
primes = np.ones(max_prime)
#print(g+1, primes.shape)
primes[0] = 0
#print(primes)
for i in range(2, max_prime):
  if primes[i] and i * 2 < g + 2:
    primes[i*2::i] = 0
    #print(i, primes)
    
primes = np.arange(max_prime)[primes == 1]
#print(primes)

factor = []
for i in primes:
  if g % i == 0:
    g //= i
    #print(g)
    factor.append(i)

#print(g, original_g, factor)
if g == original_g:
  print(len(factor) + 1)
else:
  print(len(factor))

Submission status: Wrong Answer

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

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

a_list=factorization(a)
b_list=factorization(b)

a_new=[a[0] for a in a_list]
b_new=[b[0] for b in b_list]


for i in a_new:
    if i in b_new:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
  n,m = min(x,y), max(x,y)
  while n!=0:
    n, m = m%n, n
  
  return m

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

A, B = list(map(int, input().split(" ")))
print(1+len(set(prime_factorization(gcd(A, B)))))

Submission status: Wrong Answer

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

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

def prime(n):
    if n % 2 == 0:
        return 2
    elif n % 3 == 0:
        return 3
    else:
        for i in range(2, int(n**(1/2))+1):
            if n % i == 0:
                print('aaa', i)
                return i
        return n

def div(n):
    divs = []
    tmp = n
    while True:
        if tmp == 1:
            return divs
        ret = prime(tmp)
        if ret != 0:
            divs.append(ret)
            tmp = tmp // ret
        else:
            divs.append(ret)
            break

g = gcd(a, b)
print(len(set(div(g)))+1)

Submission status: Wrong Answer

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


A, B = map(int, input().split())
g = gcd(A,B)
G = []
i = 1
while i*i<=g:
    if g%i==0:
        G.append(i)
        G.append(g/i)
    i += 1

p = {i for i in range(2,g)}
i = 2
while i*i<=g:
    if i in p:
        j = i + i
        print('j=',j)
        while j <= g:
            if j in p:
                p.remove(j)
            j += i
    i += 1
ans = set(G) & p
print(len(ans)+1)

Submission status: Wrong Answer

Solution code:
def is_prime(k):
    for i in range(2,int(k**0.5+1)):
        if k%i==0:
            return False
    return True

a,b=map(int,input().split())
ans=1
for i in range(2,int(a**0.5+1)):
    if is_prime(i):
        if b%i==0 and a%i==0:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    gcd = fractions.gcd(a, b)
    cnt = 1

    for i in range(2, int(gcd ** 0.5) + 1):
        if gcd % i == 0:
            cnt += 1
            while True:
                if gcd % i == 0:
                    gcd //= i
                else:
                    break
    print(cnt + 1 if gcd != 1 else 0)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    gcd = fractions.gcd(a, b)
    cnt = 1

    while True:
        if gcd == 1:
            break
        else:
            for i in range(2, int(gcd ** 0.5) + 1):
                if gcd % i == 0:
                    cnt += 1
                    while True:
                        if gcd % i == 0:
                            gcd //= i
                        else:
                            break
    print(cnt + 1 if gcd != 1 else 0)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
import math
A,B = map(int,input().split())
def gcd(a,b):
    if a<b : a,b = b,a
    if b==0: return a
    else: return gcd(b, a%b)
def is_prime(n,C):
    if n==1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n%k==0:
            return False
    return C%n==0
C = gcd(A,B)
ans = 1
for i in range(2,C):
    if is_prime(i,C): ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,sqrt
#from fractions import gcd
def prime(value):
    for i in range(2,int(sqrt(value)+1)):
        if value%i == 0:
            return False
    return True
def main():
    A, B = map(int,input().split())
    dic = {1:1}
    mini = min(A,B)
    maxi = max(A,B)
    for i in range(2,min(int(sqrt(maxi)) + 2,mini+1)):
        if A%i == 0 and B%i == 0:
            dic[i] = (i)
            div1 = A // i
            div2 = B // i
            if B%div1 == 0 and div1 < B:
                dic[div1] = (div1)
            if A%div2 == 0 and div2 < A:
                dic[div2] = (div2)
    ans = 0
    for key in dic.keys():
        if prime(key):
            ans += 1
    print(2 if A == B and prime(A) and A > 1 else ans)
    return 
main()

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,sqrt
#from fractions import gcd
def prime(value):
    for i in range(2,int(sqrt(value)+1)):
        if value%i == 0:
            return False
    return True
def main():
    A, B = map(int,input().split())
    dic = {1:1}
    mini = min(A,B)
    maxi = max(A,B)
    for i in range(2,min(int(sqrt(maxi)) + 2,mini)):
        if A%i == 0 and B%i == 0:
            dic[i] = (i)
            div1 = A // i
            div2 = B // i
            if B%div1 == 0 and div1 < B:
                dic[div1] = (div1)
            if A%div2 == 0 and div2 < A:
                dic[div2] = (div2)
    ans = 0
    for key in dic.keys():
        if prime(key):
            ans += 1
    print(2 if A == B and prime(A) and A > 1 else ans)
    return 
main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A, B = map(int, input().split())
a = []
b = []
for i in range(1, int(A**(1/2))+1):
    if A % i == 0:
        a.append(i)
        a.append(A//i)
for i in range(1, int(B**(1/2))+1):
    if B % i == 0:
        a.append(i)
        a.append(B//i)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,sqrt
#from fractions import gcd
def prime(value):
    for i in range(2,int(sqrt(value)+1)):
        if value%i == 0:
            return False
    return True
def main():
    A, B = map(int,input().split())
    dic = {1:1}
    mini = min(A,B)
    maxi = max(A,B)
    for i in range(2,min(int(sqrt(maxi)) + 2,mini)):
        if A%i == 0 and B%i == 0:
            dic[i] = (i)
            div1 = A // i
            div2 = B // i
            if B%div1 == 0 and div1 < B:
                dic[div1] = (div1)
            if A%div2 == 0 and div2 < A:
                dic[div2] = (div2)
    ans = 0
    for key in dic.keys():
        if prime(key):
            ans += 1
    print(ans if A != B else ans + 1)
    return 
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,sqrt
#from fractions import gcd
def prime(value):
    for i in range(2,int(sqrt(value)+1)):
        if value%i == 0:
            return False
    return True
def main():
    A, B = map(int,input().split())
    dic = {1:1}
    mini = min(A,B)
    maxi = max(A,B)
    for i in range(2,min(int(sqrt(maxi)) + 2,mini)):
        if A%i == 0 and B%i == 0:
            dic[i] = (i)
            div1 = A // i
            div2 = B // i
            if B%div1 == 0 and div1 < mini:
                dic[div1] = (div1)
            if A%div2 == 0 and div2 < mini:
                dic[div2] = (div2)
    ans = 0
    for key in dic.keys():
        if prime(key):
            ans += 1
    print(ans)
    return 
main()

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,sqrt
#from fractions import gcd
def prime(value):
    for i in range(2,int(sqrt(value)+1)):
        if value%i == 0:
            return False
    return True
def main():
    A, B = map(int,input().split())
    dic = {1:1}
    mini = min(A,B)
    maxi = max(A,B)
    for i in range(2,int(sqrt(maxi)) + 2):
        if A%i == 0 and B%i == 0:
            dic[i] = (i)
            div1 = A // i
            div2 = B // i
            if B%div1 == 0 and div1 < mini:
                dic[div1] = (div1)
            if A%div2 == 0 and div2 < mini:
                dic[div2] = (div2)
    ans = 0
    for key in dic.keys():
        if prime(key):
            ans += 1
    print(ans)
    return 
main()

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,sqrt
#from fractions import gcd
def prime(value):
    for i in range(2,int(sqrt(value)+1)):
        if value%i == 0:
            return False
    return True
def main():
    A, B = map(int,input().split())
    mini = min(A,B)
    maxi = max(A,B)
    ans = 1
    dic = {}
    for i in range(2,int(sqrt(maxi)) + 2):
        if A%i == 0 and B%i == 0:
            if prime(i) and i not in dic:
                ans += 1
                dic[i] = True
            div1 = A // i
            div2 = B // i
            if B%div1 == 0 and div1 <= mini and B // div1 not in dic and div1 != B:
                if prime(B // div1):
                    ans += 1
                    dic[B //div1] = True
            if A%div2 == 0 and div2 <= mini and A // div2 not in dic and div2 != A:
                if prime(A // div2):
                    ans += 1
                    dic[A // div2] = True
                
    print(ans)
    return 
main()

Submission status: Wrong Answer

Solution code:
import fractions
a, b = map(int, input().split())
c=fractions.gcd(a, b)
ans=1
check=0
for j in range(2,c):
    if c%j==0:
        for i in range(2,j):
            if j%i==0:
                check=0
                break
            else:
                check+=1
        check=check+3-j
        if check==1:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,sqrt
#from fractions import gcd
def prime(value):
    for i in range(2,int(sqrt(value)+1)):
        if value%i == 0:
            return False
    return True
def main():
    A, B = map(int,input().split())
    dic = {1:1}
    mini = min(A,B)
    maxi = max(A,B)
    for i in range(2,int(sqrt(maxi)) + 2):
        if A%i == 0 and B%i == 0:
            dic[i] = (i)
            div1 = A // i
            div2 = B // i
            if B%div1 == 0 and div1 <= mini:
                dic[div1] = (div1)
            if A%div2 == 0 and div2 <= mini:
                dic[div2] = (div2)
    ans = 0
    for key in dic.keys():
        if prime(key):
            ans += 1
    print(ans)
    return 
main()

Submission status: Wrong Answer

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

gcdv = gcd(a, b)

sqrt_v = int(gcdv ** 0.5) + 1
table = [True] * (sqrt_v + 1)
prime_cnt = Counter()
n = gcdv
for i in range(2, sqrt_v + 1):
    if table[i] and n % i == 0:
        while n % i == 0:
            n //= i
        prime_cnt[i] += 1

    for k in range(0, sqrt_v, i):
        table[k] = False
prime_cnt[n] += 1

print(len(prime_cnt.keys()))

Submission status: Wrong Answer

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

gcdv = gcd(a, b)

sqrt_v = int(gcdv ** 0.5) + 1
table = [True] * (sqrt_v + 1)
prime_cnt = Counter()
n = gcdv
for i in range(2, sqrt_v + 1):
    if table[i] and n % i == 0:
        while n % i == 0:
            n //= i
        prime_cnt[i] += 1
        if gcd(gcdv, i) != 1:
            is_so = False
    for k in range(0, sqrt_v, i):
        table[k] = False
prime_cnt[n] += 1

print(len(prime_cnt.keys()))

Submission status: Wrong Answer

Solution code:
def GCD(a, b):
    while b:
        a, b = b, a % b
    return a

a, b = map(int, input().split())
g = GCD(a,b)
s = 0
i = 2
while(i*i <= g):
    print("1")
    print(i)
    while g % i == 0:
        print(g)
        g = g // i
        print(g)
        s = s +1
    i = i + 1
if g>1:
        s = s+1
print(s+1)

Submission status: Wrong Answer

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

gcdv = gcd(a, b)

if gcdv == 1:
    print(1)
    sys.exit(0)
is_so = True
sqrt_v = ceil(gcdv ** 0.5)
cnt = 1
table = [True] * (sqrt_v + 1)
for i in range(2, sqrt_v + 1):
    if table[i] and gcdv % i == 0:
        cnt += 1
        if gcd(gcdv, i) != 1:
            is_so = False
    for k in range(0, sqrt_v, i):
        table[k] = False

if is_so:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
a,b = map(int,input().split())
p = []
while(b!=0):
  a,b=b,a%b
x = a
for i in range(a+1):
  p.append(True)
p[0],p[1] = False,True
for i in range(2,a+1):
  j=0
  if p[i]:
    while x%i==0:
      p[i] = True
      x//=i
    j=i*2
    if a%i!=0:
      p[i] = False
    while j<=a:
      p[j] = False
      j+=i
  if x==1:
    break
print(p.count(True))

Submission status: Wrong Answer

Solution code:
import math,fractions

A,B=map(int,input().split())
gcd=fractions.gcd(A,B)
ans=1
 
if gcd > 1:
  for i in range(2,int(math.sqrt(gcd)) + 2):
    if gcd % i == 0:
      ans += 1
      while(gcd % i == 0):
        gcd /= i
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        ans += i & 1
    print(ans/n)
    return

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

#C
def C():
    n = II()
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        d[a[i] + 1] = i + 1
    for _, v in sorted(d.items()):
        print(v, end=" ")
    print()
    return

def primes(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    """ 6以上の数であれば p (素数) <= n のlistを返す """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

#D
def D():
    a, b = LI()
    da = defaultdict(int)
    db = defaultdict(int)
    for i in range(2, int(math.sqrt(a)) + 1):
        while a % i == 0:
            a = a // i
            da[i] = 1
        while b % i == 0:
            b = b // i
            db[i] = 1
    da[a] = 1
    db[b] = 1 
    print(len(set(da.keys()) & set(db.keys())))
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        ans += i & 1
    print(ans/n)
    return

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

#C
def C():
    n = II()
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        d[a[i] + 1] = i + 1
    for _, v in sorted(d.items()):
        print(v, end=" ")
    print()
    return

def primes(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    """ 6以上の数であれば p (素数) <= n のlistを返す """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

#D
def D():
    a, b = LI()
    p = primes(10 ** 6 + 1)
    ans = 1
    f = 1
    ap = 1
    bp = 1
    for i in p:
        if a % i == b % i == 0:
            ans += 1
            f = 0
        else:
            if a % i == 0:
                ap = 0
            if b % i == 0:
                bp = 0
    if f:
        ans += ap + bp
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        ans += i & 1
    print(ans/n)
    return

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

#C
def C():
    n = II()
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        d[a[i] + 1] = i + 1
    for _, v in sorted(d.items()):
        print(v, end=" ")
    print()
    return

def primes(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    """ 6以上の数であれば p (素数) <= n のlistを返す """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

#D
def D():
    a, b = LI()
    p = primes(10 ** 6 + 1)
    ans = 1
    f = 1
    for i in p:
        if a % i == b % i == 0:
            ans += 1
            f = 0
    if f:
        ans += 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        ans += i & 1
    print(ans/n)
    return

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

#C
def C():
    n = II()
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        d[a[i] + 1] = i + 1
    for _, v in sorted(d.items()):
        print(v, end=" ")
    print()
    return

def primes(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    """ 6以上の数であれば p (素数) <= n のlistを返す """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

#D
def D():
    a, b = LI()
    p = primes(10 ** 6 + 1)
    ans = 1
    f = 1
    for i in p:
        if a % i == b % i == 0:
            ans += 1
            f = 0
    if f == 0:
        ans += 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        ans += i & 1
    print(ans/n)
    return

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

#C
def C():
    n = II()
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        d[a[i] + 1] = i + 1
    for _, v in sorted(d.items()):
        print(v, end=" ")
    print()
    return

def primes(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    """ 6以上の数であれば p (素数) <= n のlistを返す """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

#D
def D():
    a, b = LI()
    p = primes(10**7)
    ans = 1
    for i in p:
        if a % i == b % i == 0:
            ans += 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        ans += i & 1
    print(ans/n)
    return

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

#C
def C():
    n = II()
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        d[a[i] + 1] = i + 1
    for _, v in sorted(d.items()):
        print(v, end=" ")
    print()
    return

def primes(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    """ 6以上の数であれば p (素数) <= n のlistを返す """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

#D
def D():
    a, b = LI()
    p = primes(10**6)
    ans = 1
    for i in p:
        if a % i == b % i == 0:
            ans += 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        ans += i & 1
    print(ans/n)
    return

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

#C
def C():
    n = II()
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        d[a[i] + 1] = i + 1
    for _, v in sorted(d.items()):
        print(v, end=" ")
    print()
    return

def primes(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    """ 6以上の数であれば p (素数) <= n のlistを返す """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

#D
def D():
    a, b = LI()
    p = primes(int(math.sqrt(max(a, b))) + 1)
    ans = 1
    for i in p:
        if a % i == b % i == 0:
            ans += 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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