#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; struct Eratosthenes { vector isprime; vector primes; vector spf; // smallest prime factors vector mobius; Eratosthenes(int N) : isprime(N + 1, true), spf(N + 1, -1), mobius(N + 1, 1) { isprime[0] = false; isprime[1] = false; spf[1] = 1; for(int p = 2; p <= N; p++){ if(!isprime[p]) continue; primes.push_back(p); spf[p] = p; mobius[p] = -1; for(int q = p * 2; q <= N; q += p){ isprime[q] = false; if(spf[q] == -1) spf[q] = p; mobius[q] = ((q / p) % p == 0 ? 0 : -mobius[q]); } } } vector> factorize(int n) { vector> res; while(n > 1) { int p = spf[n], e = 0; while(spf[n] == p) n /= p, e++; res.push_back({p, e}); // p^e } return res; } vector divisors(int n) { vector res({1}); auto pf = factorize(n); for(auto p : pf) { int s = (int)res.size(); for(int i = 0; i < s; i++) { int v = 1; for(int j = 0; j < p.second; j++) { v *= p.first; res.push_back(res[i] * v); } } } return res; } template void fast_zeta(vector< T > &f) { int N = f.size(); vector isprime = Eratosthenes(N); for(int p = 2; p < N; p++) { if(!isprime[p]) continue; for(int k = (N - 1) / p; k >= 1; k--) { f[k] += f[k * p]; } } } template void fast_mobius(vector< T > &F) { int N = F.size(); vector isprime = Eratosthenes(N); for(int p = 2; p < N; p++) { if(!isprime[p]) continue; for(int k = 1; k * p < N; k++) { F[k] -= F[k * p]; } } } template vector< T > gcd_convolution(const vector< T > &f, const vector< T > &g) { int N = max(f.size(), g.size()); vector< T > F(N, 0), G(N, 0), H(N); for(int i = 0; i < f.size(); i++) F[i] = f[i]; for(int i = 0; i < g.size(); i++) G[i] = g[i]; fast_zeta(F); fast_zeta(G); for(int i = 1; i < N; i++) H[i] = F[i] * G[i]; fast_mobius(H); return H; } long long fast_euler_phi(int n) { auto pf = factorize(n); long long res = n; for(auto p : pf) { res *= p.first - 1; res /= p.first; } return res; } }; int main(){ cin.tie(0); ios::sync_with_stdio(0); // sum(k=A to B) k = (A+B)(B-A+1)/2 // A=B -> [L,R] の素数の個数 // A A+1=B, (2A+1)が素数 // pi(R) - pi(L-1) + pi(2R) - pi(2L) int L,R; cin >> L >> R; Eratosthenes sieve(2 * R); vector pi(2 * R + 2, 0); rep(i,pi.size()-1) pi[i + 1] += pi[i] + sieve.isprime[i + 1]; cout << pi[R] - pi[L - 1] + pi[2 * R] - pi[2 * L] << endl; }