#include <bits/stdc++.h>
using namespace std;
void segmentedSieve(long long L, long long R) {
  long long lim = sqrt(R);
  vector<bool> mark(lim + 1, false);
  vector<long long> primes;
  for (long long i = 2; i <= lim; ++i) {
    if (!mark[i]) {
      primes.emplace_back(i);
      for (long long j = i * i; j <= lim; j += i) mark[j] = true;
    }
  }
  int buenos = 0;
  long long len = ceil(sqrt(R - L + 1));
  for (long long bloques = 0; bloques < len; ++bloques) {
    long long l = L + len * bloques + 1;
    if (bloques == 0) l = L;
    long long r = min(R, L + len * (bloques + 1));
    if (l > r) break;
    vector<bool> isPrime(r - l + 1, true);
    for (long long i : primes)
      for (long long j = max(i * i, (l + i - 1) / i * i); j <= r; j += i)
        isPrime[j - l] = false;
    if (l == 1) isPrime[0] = false;
    for (long long i = l; i <= r; ++i) {
      if (i == 2 || (isPrime[i - l] && i % 4 == 1)) {
        buenos++;
      }
    }
  }
  cout << buenos << '\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(20) << fixed;
  long long l, r;
  cin >> l >> r;
  segmentedSieve(l, r);
}
