#include #include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; /*-------------------------------------------------*/ vector sieve_of_eratosthenes(int num) { vector res(num + 1, true); if (num >= 0) { res[0] = false; if (num >= 1) res[1] = false; } for (int i = 2; i * i <= num; ++i) if (res[i]) { for (int j = i * i; j <= num; j += i) res[j] = false; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int n, p; cin >> n >> p; vector prime = sieve_of_eratosthenes(n); if (p == 1 || (prime[p] && p * 2 > n)) { cout << 1 << '\n'; return 0; } int ans = n - 1; for (int i = n; i > n / 2; --i) { if (prime[i]) --ans; } cout << ans << '\n'; return 0; }