#include <bits/stdc++.h>
using namespace std;
bitset<300000026> b;
bitset<300000026> bee;
vector<int> vec, vect;
int main() {
  std::ios::sync_with_stdio(false);
  int l, r;
  cin >> l >> r;
  int i, j, sumi = 0;
  for (i = 2; i * i <= r + 3; i++) {
    if (b[i]) continue;
    for (j = i * i; j <= r + 2; j += i) {
      b[j] = 1;
    }
  }
  for (i = 1; i * i < r + 1; i += 2) {
    vec.push_back(i * i);
  }
  for (j = 2; j * j < r + 1; j += 2) {
    vect.push_back(j * j);
  }
  for (i = 0; i < vect.size(); i++) {
    for (j = 0; j < vec.size(); j++) {
      if (vect[i] + vec[j] <= r && vect[i] + vec[j] >= l &&
          bee[vect[i] + vec[j]] == 0 && b[vect[i] + vec[j]] == 0) {
        bee[vect[i] + vec[j]] = 1;
        sumi++;
      }
      if (vect[i] + vec[j] > r) break;
    }
  }
  if (l <= 2 && r >= 2) sumi++;
  cout << sumi << endl;
}
