#pragma GCC optimize("O3", "unroll-loops") // 請求 GCC 進行最激進的優化
#include <cstdio> // 使用 C-style I/O,速度最快
#include <cstring> // 使用 memset,高速重置記憶體
#include <algorithm> // 使用 std::max
// --- 全局變數靜態化,消除所有 std::vector 開銷 ---
const int PRIME_COUNT_MAX = 1229; // 10000 以內的質數數量
const int SIEVE_LIMIT = 10000;
int primes[PRIME_COUNT_MAX];
int prime_count = 0;
static char is_composite_range[1002];
void precompute_sieve() {
static bool is_composite_sieve[SIEVE_LIMIT + 1];
is_composite_sieve[0] = is_composite_sieve[1] = true;
for (int p = 2; p * p <= SIEVE_LIMIT; ++p) {
if (!is_composite_sieve[p]) {
for (int i = p * p; i <= SIEVE_LIMIT; i += p) {
is_composite_sieve[i] = true;
}
}
}
for (int p = 2; p <= SIEVE_LIMIT; ++p) {
if (!is_composite_sieve[p]) {
primes[prime_count++] = p;
}
}
}
int main() {
precompute_sieve();
long long a, b;
while (scanf("%lld %lld", &a, &b) == 2) {
if (a > b) {
printf("0\n");
continue;
}
long long range_size = b - a + 1;
memset(is_composite_range, 0, range_size);
for (int i = 0; i < prime_count; ++i) {
long long p_ll = primes[i];
if (p_ll * p_ll > b) break;
long long start_num = (a + p_ll - 1) / p_ll * p_ll;
long long start_idx = std::max(start_num, p_ll * p_ll) - a;
for (long long j = start_idx; j < range_size; j += p_ll) {
is_composite_range[j] = 1;
}
}
if (a == 1) {
is_composite_range[0] = 1;
}
int count = 0;
for (long long i = 0; i < range_size; ++i) {
if (is_composite_range[i] == 0) {
count++;
}
}
printf("%d\n", count);
}