import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B = LI()

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

Ad = make_divisors(A)
Bd = make_divisors(B)
# c = list(Ad.intersection(Bd))
c = list(set(Ad) & set(Bd))

def is_prime_custom(n):
    # custom
    if n == 1: return True

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

count = 0
for i in c:
    if is_prime_custom(i):
        count += 1
print(count) import bisect,collections,copy,heapq,itertools,math,string bisect collections copy heapq itertools math string import numpy as np numpy from numba import njit import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def _S(): return sys.stdin.readline().rstrip() _S def I(): return int(sys.stdin.readline().rstrip()) I def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) LI def LS(): return list(sys.stdin.readline().rstrip().split()) LS A,B = LI() A LI() LI B 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 make_divisors divisors = [] 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)

     i range(1, int(n**0.5)+1) range 1 int(n**0.5)+1 int(n**0.5) int n**0.5 n 0.5 1 if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

     n % i == 0 n % i n i 0 divisors.append(i) divisors.append divisors append i if i != n // i:
                divisors.append(n//i)

     i != n // i i n // i n i divisors.append(n//i) divisors.append divisors append n//i n i divisors.sort() divisors.sort divisors sort return divisors divisors n n Ad = make_divisors(A) Ad make_divisors(A) make_divisors A Bd = make_divisors(B) Bd make_divisors(B) make_divisors B c = list(set(Ad) & set(Bd)) c list(set(Ad) & set(Bd)) list set(Ad) & set(Bd) set(Ad) set Ad set(Bd) set Bd def is_prime_custom(n):
    # custom
    if n == 1: return True

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True is_prime_custom if n == 1: return True

     n == 1 n 1 for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

     k range(2, int(math.sqrt(n)) + 1) range 2 int(math.sqrt(n)) + 1 int(math.sqrt(n)) int math.sqrt(n) math.sqrt math sqrt n 1 if n % k == 0:
            return False

     n % k == 0 n % k n k 0 return False False return True True n n count = 0 count 0 for i in c:
    if is_prime_custom(i):
        count += 1 i c if is_prime_custom(i):
        count += 1 is_prime_custom(i) is_prime_custom i count += 1 count 1 print(count) print count A,B = LI() LI() A c = list(set(Ad) & set(Bd)) list(set(Ad) & set(Bd)) c def is_prime_custom(n):
    # custom
    if n == 1: return True

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True def is_prime_custom(n):
    # custom
    if n == 1: return True

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True is_prime_custom count += 1 1 count def LS(): return list(sys.stdin.readline().rstrip().split()) def LS(): return list(sys.stdin.readline().rstrip().split()) LS B = LI() LI() B count = 0 0 count def _S(): return sys.stdin.readline().rstrip() def _S(): return sys.stdin.readline().rstrip() _S Bd = make_divisors(B) make_divisors(B) Bd Ad = make_divisors(A) make_divisors(A) Ad def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I 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 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 make_divisors def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) LI
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B = LI()

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

Ad = make_divisors(A)
Bd = make_divisors(B)
# c = list(Ad.intersection(Bd))
c = list(set(Ad) & set(Bd))

def is_prime_custom(n):
    # custom
    if n == 1: return True

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

count = 0
for i in c:
    if is_prime_custom(i):
        count += 1
print(count)