from itertools import chain def prime_set(N): """ Nまでの素数のsetを返す """ if N < 4: return ({}, {}, {2}, {2, 3})[N] Nsq = int(N ** 0.5 + 0.5) + 1 primes = {2, 3} | set(chain(range(5, N + 1, 6), range(7, N + 1, 6))) for i in range(5, Nsq, 2): if i in primes: primes -= set(range(i * i, N + 1, i * 2)) return primes U = 2 * 10 ** 6 + 10 Prime = prime_set(U) L, R = map(int, input().split()) ans = 0 for i in range(L, R+1): if i in Prime: ans += 1 for i in range(L, R): if 2 * i + 1 in Prime: ans += 1 print(ans)