#include using namespace std; #define rep(i, n) for(int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for(int i = a; i < (int)b; ++i) #define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i) typedef long long ll; typedef long double ld; const int Inf = 1e9; const double EPS = 1e-9; const int MOD = 1e9 + 7; class LinearSieve { public: vector lp, pr; LinearSieve() {} LinearSieve(int n) { lp.resize(n + 1); lp[0] = -1, lp[1] = -1; init(n); } void init(int x) { FOR (i, 2, x + 1) { if (lp[i] == 0) { lp[i] = i; pr.push_back(i); } for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && (ll)i * pr[j] <= x; ++j) { lp[i * pr[j]] = pr[j]; } } } bool isPrime(int x) { return lp[x] == x; } vector factorList(int x) { vector res; while (x != 1) { res.push_back(lp[x]); x /= lp[x]; } return res; } vector > factorize(int x) { vector p = factorList(x); if (p.size() == 0) return {}; vector > res(1, make_pair(p[0], 0)); rep (i, p.size()) { if (res.back().first == p[i]) { res.back().second++; } else { res.emplace_back(p[i], 1); } } return res; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(0); int n, p; cin >> n >> p; LinearSieve ls = LinearSieve(n + 10); if (p > n / 2 && ls.isPrime(p)) { cout << 1 << endl; return 0; } else if (ls.isPrime(p)) { cout << 2 << endl; return 0; } int cnt = 0; FOR (i, n / 2, n + 1) { if (ls.isPrime(i)) cnt++; } cout << n - cnt << endl; return 0; }