#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535897932384626433832795;
double eps = 1e-14;
char ch[1 << 20];
inline string gs() {
  scanf("%s", ch);
  return string(ch);
}
inline int gi() {
  int x;
  scanf("%d", &x);
  return x;
}
void error() {
  int ttt = 0;
  cout << 7 / ttt;
}
long long gcd(long long a, long long b) { return (!a) ? b : gcd(b % a, a); }
const long long mod = 1000 * 1000 * 1000 + 7;
inline long long MUL(long long a, long long b) { return a * b % mod; }
inline long long ADD(long long a, long long b) {
  return (a + b >= mod) ? a + b - mod : a + b;
}
inline long long SUB(long long a, long long b) {
  return (a - b < 0) ? a + mod - b : a - b;
}
const int BLOCK = 10000;
int nP[20000], B[BLOCK];
int P[20000], C;
int go(int n1, int n) {
  C = 0;
  for (int i = 2; i * i <= n; ++i)
    if (!nP[i]) {
      P[C++] = i;
      for (int j = i + i; j * j <= n; j += i) nP[j] = 1;
    }
  int res = 0;
  for (int k = 0, mxk = n / BLOCK; k <= mxk; ++k) {
    memset(B, 0, sizeof(B));
    int beg = k * BLOCK;
    for (int i = 0; i < C; ++i)
      for (int j = max((beg + P[i] - 1) / P[i], 2) * P[i] - beg; j < BLOCK;
           j += P[i])
        B[j] = 1;
    if (!k) B[0] = B[1] = 1;
    int x = beg;
    for (int i = 0; i < BLOCK && beg + i <= n; ++i) {
      if (!B[i] && x >= n1 && ((x & 3) == 1 || x == 2)) ++res;
      ++x;
    }
  }
  return res;
}
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int r = go(a, b);
  printf("%d\n", r);
  return 0;
}
