N,P = map(int, input().split()) if P > 1: L = [0]*(N+1) n = 2 num = P while n <= P**0.5: if P%n == 0: num = n break n += 1 if num*2 <= N: ans = N//2-1 for i in range(N//2+1, N+1): n = 2 while n <= i**0.5: if i%n == 0: ans += 1 break n += 1 else: ans = 1 print(ans)