#include #include #include int main() { int N, P; std::cin >> N >> P; assert(1 <= N and N <= 1000000); assert(1 <= P and P <= N); std::vector isPrime(N + 1, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i <= N; i++) { if (not isPrime[i]) { continue; } for (int j = 2; i * j <= N; j++) { isPrime[i * j] = false; } } int isolated = 1; for (int i = N; i * 2 > N; i--) { if (isPrime[i]) { isolated++; } } const bool solitude = P == 1 or (P * 2 > N and isPrime[P]); if (solitude) { std::cout << 1 << std::endl; } else { std::cout << N - isolated << std::endl; } return 0; }