#include <bits/stdc++.h>
using namespace std;
int a[1005] = {
    12980, 11542, 11062, 10845, 10593, 10466, 10390, 10176, 10185, 10044, 10091,
    9895,  9949,  9902,  9804,  9750,  9758,  9615,  9661,  9624,  9633,  9497,
    9606,  9512,  9393,  9508,  9403,  9386,  9439,  9391,  9343,  9369,  9293,
    9288,  9271,  9244,  9251,  9279,  9289,  9265,  9216,  9124,  9223,  9104,
    9131,  9110,  9071,  9163,  9080,  9060,  9036,  8940,  9132,  9015,  9074,
    8978,  9049,  8994,  9021,  8989,  8981,  8873,  9022,  8967,  8937,  8904,
    8937,  8844,  8929,  8874,  8917,  8888,  8902,  8848,  8789,  8874,  8893,
    8858,  8823,  8755,  8881,  8813,  8815,  8784,  8750,  8819,  8783,  8789,
    8844,  8768,  8716,  8795,  8717,  8766,  8780,  8719,  8716,  8759,  8675,
    8773,  8740,  8775,  8731,  8598,  8685,  8653,  8685,  8625,  8663,  8684,
    8702,  8641,  8703,  8510,  8623,  8590,  8641,  8663,  8639,  8572,  8665,
    8658,  8546,  8703,  8551,  8566,  8652,  8667,  8533,  8649,  8567,  8625,
    8583,  8525,  8603,  8609,  8507,  8540,  8553,  8484,  8597,  8485,  8478,
    8516,  8549,  8485,  8618,  8463,  8522,  8523,  8486,  8523,  8514,  8402,
    8524,  8525,  8482,  8532,  8517,  8509,  8444,  8537,  8449,  8469,  8485,
    8464,  8452,  8447,  8498,  8438,  8375,  8506,  8381,  8468,  8364,  8460,
    8366,  8463,  8381,  8438,  8393,  8419,  8355,  8494,  8369,  8411,  8435,
    8425,  8414,  8324,  8415,  8447,  8370,  8341,  8371,  8398,  8332,  8302,
    8407,  8425,  8348,  8429,  8423,  8272,  8385,  8265,  8421,  8367,  8275,
    8351,  8333,  8338,  8419,  8382,  8390,  8277,  8391,  8292,  8392,  8306,
    8349,  8354,  8294,  8293,  8421,  8283,  8312,  8340,  8329,  8318,  8303,
    8359,  8289,  8304,  8286,  8284,  8252,  8310,  8331,  8252,  8314,  8314,
    8344,  8210,  8270,  8316,  8207,  8304,  8278,  8288,  8248,  8361,  8295,
    8267,  8225,  8249,  8308,  8291,  8166,  8238,  8264,  8250,  8180,  8266,
    8248,  8251,  8197,  8272,  8197,  8264,  8277,  8239,  8265,  8249,  8197,
    8252,  8276,  8118,  8256,  8351,  8130,  8262,  8168,  8201,  8286,  8232,
    8173,  8182,  8189,  8155,  8274,  8187,  8264,  8201,  8254,  8154,  8172,
    8254,  8164,  8140,  8171,  8222,  8129,  8152,  8206,  8115,  8175,  8224,
    8226,  8171,  8146,  8166,  8088,  8269,  8083,  8209,  8233,  8142,  8204,
    8185,  8122,  8149,  8194,  8156,  8124,  8162,  8150,  8133,  8196,  8066,
    8132,  8155,  8121,  8170,  8102,  8131,  8146,  8134,  8144,  8106,  8164,
    8168,  8158,  8047,  8127,  8064,  8181,  8187,  8101,  8109,  8120,  8129,
    8068,  8132,  8075,  8093,  8129,  8186,  8108,  8034,  8131,  8162,  8130,
    8157,  8137,  8095,  8165,  7977,  8128,  8111,  8060,  8103,  8194,  8182,
    8030,  8139,  8056,  8068,  8034,  7976,  8066,  8024,  8140,  8074,  8089,
    8076,  8071,  8092,  7980,  8048,  8070,  8108,  8013,  8135,  8071,  8006,
    8089,  8078,  8076,  8052,  8037,  7982,  8102,  8088,  8031,  8024,  8067,
    8006,  8047,  8114,  8106,  8074,  8022,  8080,  8082,  8038,  8009,  8072,
    7984,  8086,  8081,  8001,  7989,  8121,  8060,  8034,  8084,  7984,  8069,
    8134,  8021,  8067,  7996,  7981,  8002,  8044,  8034,  8097,  8073,  7988,
    8060,  8023,  8018,  8024,  7982,  7961,  8016,  8061,  8038,  8024,  8032,
    7925,  7980,  7957,  8053,  8025,  7932,  7993,  8056,  7913,  7909,  8031,
    8001,  8042,  8055,  8057,  8090,  7923,  7968,  7924,  7956,  8022,  8026,
    8005,  8012,  7943,  8017,  8023,  7960,  8027,  8024,  7998,  7962,  7986,
    7996,  7939,  8029,  7995,  7973,  8011,  7960,  8040,  7872,  7988,  7959,
    7958,  7922,  7982,  7937,  8003,  7930,  7947,  7923,  7917,  7959,  7964,
    7973,  7801,  7952,  7944,  7923,  8017,  8059,  7940,  7910,  7909,  7996,
    7877,  8010,  7909,  8034,  7972,  7981,  7862,  8027,  7888,  7971,  7910,
    7817,  7934,  7899,  8008,  7928,  7931,  7959,  7890,  8063,  7855,  7934,
    7885,  7930,  7969,  7946,  7899,  7948,  8041,  7940,  7935,  7939,  7866,
    7870,  7921,  7881,  7882,  8026,  7865,  7900,  7892,  7918,  7942,  7904,
    7893,  7953,  8002,  7996,  7870,  7906,  7934,  7869,  7866,  7966,  7905,
    7897,  7921,  7906,  7914,  7880,  7996,  7959,  7852,  7896,  7908,  7884,
    7898,  7933,  7880,  7894,  7905,  7883,  7915,  7891,  7918,  7913,  7975,
    7854,  7902,  7957,  7904,  7907,  7986,  7877,  7875,  7833,  7815,  7930,
    7888,  7912,  7834,  7841,  7833,  7870,  7887,  7877,  7878,  7938,  7948,
    7875,  7941,  7795,  7890,  7874,  7860,  7915,  7916,  7916,  7775,  7899,
    7869,  7915,  7793,  7961,  7887,  7866,  7910,  7790,  7766,  7821,  7818,
    7814,  7813,  7818,  7902,  7960,  7897,  7790,  7910,  7874,  7851,  7848,
    7916,  7823,  7863,  7868,  7846,  7854,  7796,  7838,  7776,  7784,  7868,
    7785,  7918,  7844,  7774,  7927,  7786,  7959,  7849,  7822,  7833,  7933,
    7813,  7865,  7937,  7806,  7807,  7824,  7916,  7841,  7856,  7741,  7909,
    7873,  7788,  7800,  7839,  7817,  7819,  7775,  7922,  7800,  7885,  7748,
    7806,  7794,  7839,  7784,  7798,  7939,  7826,  7874,  7795,  7775,  7890,
    7909,  7778,  7837,  7839,  7876,  7858,  7809,  7838,  7779,  7876,  7761,
    7829,  7902,  7851,  7836,  7844,  7895,  7810,  7808,  7777,  7820,  7772,
    7796,  7809,  7750,  7771,  7838,  7808,  7766,  7842,  7795,  7773,  7787,
    7851,  7800,  7778,  7871,  7818,  7780,  7858,  7790,  7863,  7720,  7859,
    7763,  7921,  7749,  7732,  7870,  7767,  7773,  7878,  7842,  7849,  7635,
    7721,  7775,  7706,  7817,  7835,  7771,  7724,  7835,  7759,  7837,  7730,
    7782,  7774,  7829,  7808,  7818,  7816,  7743,  7711,  7820,  7745,  7767,
    7732,  7846,  7752,  7856,  7766,  7771,  7820,  7761,  7863,  7760,  7835,
    7754,  7822,  7780,  7815,  7711,  7774,  7804,  7686,  7827,  7870,  7729,
    7812,  7797,  7717,  7751,  7681,  7680,  7799,  7747,  7732,  7836,  7728,
    7745,  7816,  7840,  7822,  7779,  7727,  7699,  7759,  7757,  7756,  7729,
    7681,  7711,  7867,  7752,  7786,  7747,  7709,  7731,  7767,  7720,  7800,
    7825,  7691,  7742,  7671,  7766,  7725,  7713,  7733,  7813,  7777,  7711,
    7789,  7825,  7782,  7679,  7793,  7751,  7787,  7704,  7694,  7831,  7844,
    7694,  7738,  7739,  7791,  7825,  7695,  7791,  7668,  7722,  7759,  7771,
    7824,  7775,  7747,  7681,  7774,  7866,  7690,  7825,  7760,  7664,  7726,
    7786,  7716,  7779,  7717,  7826,  7777,  7741,  7693,  7673,  7706,  7743,
    7751,  7697,  7738,  7707,  7772,  7783,  7768,  7607,  7687,  7706,  7803,
    7719,  7633,  7667,  7834,  7672,  7750,  7701,  7650,  7655,  7820,  7727,
    7794,  7685,  7798,  7663,  7740,  7733,  7734,  7719,  7685,  7713,  7699,
    7731,  7778,  7667,  7661,  7697,  7684,  7683,  7685,  7747,  7721,  7691,
    7728,  7633,  7750,  7771,  7703,  7642,  7712,  7658,  7715,  7713,  7774,
    7680,  7750,  7664,  7736,  7588,  7774,  7673,  7692,  7640,  7681,  7802,
    7730,  7701,  7696,  7687,  7708,  7762,  7573,  7698,  7781,  7654,  7750,
    7660,  7805,  7742,  7607,  7730,  7725,  7729,  7612,  7654,  7728,  7691,
    7673,  7742,  7703,  7697,  7669,  7680,  7708,  7660,  7600,  7817,  7629,
    7719,  7629,  7656,  7749,  7728,  7625,  7591,  7611,  7674,  7708};
bool prime(int x) {
  if (x == 1) return false;
  int i;
  for (i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) return false;
  }
  return true;
}
int main() {
  int i, l, r, p, q, s = 0;
  scanf("%d%d", &l, &r);
  if (l <= 2 && r >= 2)
    s = 1;
  else
    s = 0;
  p = l / 300000;
  q = r / 300000;
  for (i = p + 1; i <= q - 1; i++) s += a[i];
  while (l % 4 != 1) l++;
  while (r % 4 != 1) r--;
  if (p == q) {
    for (i = l; i <= r; i += 4) {
      if (prime(i)) s++;
    }
    printf("%d\n", s);
    return 0;
  }
  for (i = l; i <= (p + 1) * 300000; i += 4) {
    if (prime(i)) s++;
  }
  for (i = q * 300000 + 1; i <= r; i += 4) {
    if (prime(i)) s++;
  }
  printf("%d\n", s);
  return 0;
}
