import math def sieve_of_eratosthenes(n): prime = [True for i in range(n+1)] prime[0] = False prime[1] = False sqrt_n = math.ceil(math.sqrt(n)) for i in range(2, sqrt_n): if prime[i]: for j in range(2*i, n+1, i): prime[j] = False return prime class UnionFind: def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n+1) self.size = [1 for _ in range(n+1)] # 検索 def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # 併合 def union(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 同じ集合に属するか判定 def same_check(self, x, y): return self.find(x) == self.find(y) n,p = map(int,input().split()) ki = UnionFind(n+1) chk = [0]*(n+1) prm = sieve_of_eratosthenes(n) pm = [] for i in range(n+1): if prm[i] == True: pm.append(i) tmp = 2 while tmp*2 <= n: #print(tmp*2,tmp,tmp) ki.union(2,tmp*2) tmp += 1 for i in range(1,len(pm)): now = pm[i] idx = i-1 while now*pm[idx] <= n: #print(now,now,prm[idx]) ki.union(now,now*pm[idx]) idx += 1 if idx >= len(pm): break ans = 0 idx = ki.find(p) for i in range(n): #print(ki.par[i+1]) if ki.find(i+1) == idx: ans += 1 print(ans)