INF = 10 ** 10 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) from collections import deque def main(): n, P = map(int,input().split()) G = [[] for _ in range(n + 1)] primes = [1] * (n + 1) for p in range(2,n + 1): if primes[p]: for i in range(2 * p,n + 1,p): primes[i] = 0 G[i].append(p) G[p].append(i) stack = [] stack.append(P) visited = [0] * (n + 1) visited[P] = 1 while stack: p = stack.pop() for v in G[p]: if visited[v]: continue else: visited[v] = 1 stack.append(v) print(sum(visited)) if __name__ == '__main__': main()