import scala.io.StdIn._

object Main extends App {
  val Array(a, b) = readLine.split(" ").map(_.toLong)

  def lcm(l: Long, r: Long): Long = l % r match {
    case 0 => r
    case x => lcm(r, x)
  }

  val primes: Stream[Int] = 2 #:: (Stream.from(3, 2) filter {n =>
    primes takeWhile {_ <= Math.sqrt(n).toInt} forall {n % _ != 0}
  })

  def div(n: Long, ps: Stream[Int], cnt: Int): Int = {
    val p = ps.head
    if (n < p * p) {
      cnt + (if (n == 1) 1 else 2)
    } else {
      def divP(l: Long): Long = if (l % p == 0) divP(l / p) else l
      divP(n) match {
        case `n` => div(n, ps.tail, cnt)
        case other => div(other, ps.tail, cnt + 1)
      }
    }
  }

  println(div(lcm(a, b), primes, 0))
}