import java.util.*

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" "). map { it.toLong() }
    val a = gcd(N, K)
    val list = factorization(a)
    var ans = list.size
    if (!list.contains(1L)) { ans++ }
    println(ans)
}

tailrec fun gcd(a: Long, b: Long): Long = if(b == 0L) a else gcd(b, a % b)

fun decom(v : Long) : List<Long> {
    var value = v
    var list = emptySet<Long>()
    var i = 2L
    while(value !=1L ) {
        if (value%i==0L) {
            list = list + i
            value/= i;
        } else i++;
    }
    return list.toList()
}

fun factorization(n : Long) : List<Long> {
    var list = emptySet<Long>()
    var tmp = n
    for (i in 2L .. Math.sqrt(n.toDouble()).toLong()) {
        if (tmp % i.toLong() == 0L) {
            var count = 0
            while (tmp % i ==0L) {
                count++
                tmp = tmp / i
            }
            list += i.toLong()
        }
    }
    if (tmp != 1L) {
        list += tmp
    }
    if (list.isEmpty()) {
        list += n
    }
    return list.toList()
}