#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define debug(x) cerr << #x << ": " << x << endl using namespace std; typedef long long ll; typedef pair Pll; typedef pair Pii; const ll MOD = 1000000007; const long double EPS = 1e-10; const int dyx[4][2] = { { 0, 1}, {-1, 0}, {0,-1}, {1, 0} }; vector primes; int is_not_prime[1000001], connected[1000001]; int main() { std::ios::sync_with_stdio(0); cin.tie(0); int n, p; cin >> n >> p; if(p == 1) { cout << "1\n"; return 0; } is_not_prime[1] = 1; for(int i=2;i<=n;++i) { if(is_not_prime[i]) continue; primes.push_back(i); int j = i+i; while(j <= n) { is_not_prime[j] = 1; j += i; } } int min_i = (is_not_prime[p]?0:distance(primes.begin(), (lower_bound(primes.begin(), primes.end(), p)))); int max_i = (is_not_prime[p]?distance(primes.begin(), (--upper_bound(primes.begin(), primes.end(), n/primes[min_i]))):min_i); // cerr << primes[min_i] << " " << primes[max_i] << endl; for(int i=min_i;i<=max_i;++i) { for(int j=primes[i];j<=n;j+=primes[i]) { connected[j] = 1; } } int ans = 0; for(int i=1;i<=n;++i) { if(connected[i]) ++ans; } cout << ans << endl; return 0; }