import math a, b = map(int, input().split()) c = 0 while a%b==0: if b==1: c = 1 break a //= b c += 1 d = a for i in range(2, math.ceil(math.sqrt(a))): if a%i==0: tmp = 1 while a%i==0: tmp += 1 a //= i c *= tmp if a==d and b!=1: print(c*2) else: print(c)