#include <bits/stdc++.h>
using namespace std;
int L, R;
int ans = 0;
void simpleSieve(int limit, vector<int> &prime) {
  bool mark[limit + 1];
  memset(mark, true, sizeof(mark));
  for (int p = 2; p * p < limit; p++) {
    if (mark[p]) {
      for (int i = p * 2; i < limit; i += p) mark[i] = false;
    }
  }
  for (int p = 2; p < limit; p++) {
    if (mark[p]) {
      prime.push_back(p);
      if (L <= p && p <= R && p % 4 == 1) ans++;
    }
  }
}
void segmentedSieve(int n) {
  int limit = floor(sqrt(n)) + 1;
  vector<int> prime;
  simpleSieve(limit, prime);
  int low = limit;
  int high = 2 * limit;
  while (low < n) {
    bool mark[limit + 1];
    memset(mark, true, sizeof(mark));
    for (int i = 0; i < prime.size(); i++) {
      int loLim = floor(low / prime[i]) * prime[i];
      if (loLim < low) loLim += prime[i];
      for (int j = loLim; j < high; j += prime[i]) mark[j - low] = false;
    }
    for (int i = low; i < high; i++)
      if (mark[i - low])
        if (L <= i && i <= R && i % 4 == 1) ans++;
    low = low + limit;
    high = high + limit;
    if (high >= n) high = n;
  }
}
int main() {
  cin >> L >> R;
  segmentedSieve(R + 1);
  if (L <= 2 && 2 <= R) ans++;
  cout << ans << endl;
  return 0;
}
