import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b] <- getIntList
    let m = gcd a b
    print . length $ ps m 2

ps 1 _ = [1]
ps m k | m `mod` k == 0 = k : (ps (d m k) k)
       | otherwise = ps m (k + 1)

d m k | m `mod` k /= 0 = m
      | otherwise = d (m `div` k) k