a, b = gets.chomp.split.map(&:to_i)

a, b = b, a if a > b
until a == 0
  a, b = b%a, a
end

# bが最大公約数
k = []

1.upto((b/2).ceil) do |i|
  k.push(i) if b % i == 0
end
k.push(b)

def prime_or_1?(n)
  return true if n == 1
  return true  if n == 2 or n == 3
  return false if (n % 2).zero?
  3.step(Math.sqrt(n).to_i, 2) {|i| return false if (n % i).zero?}
  true
end

p k.select{ |i| prime_or_1?(i) }.size
