module Main where

import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Char
-- import Debug.Trace

main :: IO ()
main = do
  [a, b] <- unfoldr (BS.readInteger . BS.dropWhile isSpace) <$> BS.getLine
  let g = gcd a b
  print $ count 0 g ((floor $ sqrt $ fromIntegral g) + 1) primes
  where
    count c x ub (p:ps)
      | p > ub = 
        -- trace ("d " ++ show p) $ 
        (c + 1)
      | x `mod` p == 0 = 
        -- trace ("y " ++ show p) $ 
        count (c + 1) x ub ps
      | otherwise = 
        -- trace ("n " ++ show p) $ 
        count c x ub ps

-- http://qiita.com/myuon_myon/items/ad006568bd187223f494#2-4
primes = 2:3:[x|i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x] where
  isPrime n = null [i|i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]
