require "prime"
a,b = gets.split.map(&:to_i)

def dasu(num)
  result = []
  i = 2
  while i <= num do
    if num % i == 0
      result << i
      num = num / i
    else
      i += 1
    end
  end
  return result
end

def dasu2
  return [1] if self == 1
  first, *rest = Prime.prime_division(self).map do |p, k|
    (0..k).map{|i| p**i}
  end
  first.product(*rest).map do |a|
    a.inject(&:*)
  end.sort
end

first = dasu2(a)
second = dasu2(b)

yaku = first & second
yaku << 1
print yaku.count
