import numpy as np



q = int(input())



# 素数列挙

n = 10**5 + 1

primes = set(range(3, n+1, 2))

for i in range(3, int(n**0.5+1)):

    primes.difference_update(range(i*2, n+1, i))

primes.add(2)



arr = np.array(list(primes))

arr = np.bincount(arr)



# 素数かつ2017に似た数を列挙

like_2017 = np.zeros(n, bool)

for i in np.where(arr == 1)[0]:

    if (i + 1) // 2 in primes:

        like_2017[i] = True



like_2017 = like_2017.cumsum()





def cnt_primes(l, r):

    return like_2017[r] - like_2017[l - 1]





ans = []

for _ in range(q):

    tmp = 0

    l, r = map(int, input().split())

    tmp += cnt_primes(l, r)

    ans.append(tmp)



print(*ans, sep="\n")

from itertools import accumulate

n = 10**5 + 1

primes = set(range(3, n+1, 2))



for i in range(3, int(n**0.5+1)):

    primes.difference_update(list(range(i*2, n+1, i)))

primes.add(2)





def like_2017(n):

    return n in primes and (n + 1) // 2 in primes





result = [0] * 10**5

for i in range(1, 10**5 + 1, 2):

    result[i] = like_2017(i)





cumsum = list(accumulate(result))



q = int(eval(input()))



for _ in range(q):

    l, r = list(map(int, input().split()))

    print((cumsum[r] - cumsum[l - 1]))
import numpy as np

q = int(input())
# 素数列挙
n = 10**5 + 1
primes = set(range(3, n + 1, 2))
for i in range(3, int(n**0.5 + 1)):
    primes.difference_update(range(i * 2, n + 1, i))
primes.add(2)
arr = np.array(list(primes))
arr = np.bincount(arr)
# 素数かつ2017に似た数を列挙
like_2017 = np.zeros(n, bool)
for i in np.where(arr == 1)[0]:
    if (i + 1) // 2 in primes:
        like_2017[i] = True
like_2017 = like_2017.cumsum()


def cnt_primes(l, r):
    return like_2017[r] - like_2017[l - 1]


ans = []
for _ in range(q):
    tmp = 0
    l, r = map(int, input().split())
    tmp += cnt_primes(l, r)
    ans.append(tmp)
print(*ans, sep="\n")

from itertools import accumulate

n = 10**5 + 1
primes = set(range(3, n + 1, 2))
for i in range(3, int(n**0.5 + 1)):
    primes.difference_update(list(range(i * 2, n + 1, i)))
primes.add(2)


def like_2017(n):
    return n in primes and (n + 1) // 2 in primes


result = [0] * 10**5
for i in range(1, 10**5 + 1, 2):
    result[i] = like_2017(i)
cumsum = list(accumulate(result))
q = int(eval(input()))
for _ in range(q):
    l, r = list(map(int, input().split()))
    print((cumsum[r] - cumsum[l - 1]))

-import numpy as np +from itertools import accumulate -q = int(input()) -# 素数列挙 -    primes.difference_update(range(i * 2, n + 1, i)) +    primes.difference_update(list(range(i * 2, n + 1, i))) -arr = np.array(list(primes)) -arr = np.bincount(arr) -# 素数かつ2017に似た数を列挙 -like_2017 = np.zeros(n, bool) -for i in np.where(arr == 1)[0]: -    if (i + 1) // 2 in primes: -        like_2017[i] = True -like_2017 = like_2017.cumsum() -def cnt_primes(l, r): -    return like_2017[r] - like_2017[l - 1] +def like_2017(n): +    return n in primes and (n + 1) // 2 in primes -ans = [] +result = [0] * 10**5 +for i in range(1, 10**5 + 1, 2): +    result[i] = like_2017(i) +cumsum = list(accumulate(result)) +q = int(eval(input())) -    tmp = 0 -    l, r = map(int, input().split()) -    tmp += cnt_primes(l, r) -    ans.append(tmp) -print(*ans, sep="\n") +    l, r = list(map(int, input().split())) +    print((cumsum[r] - cumsum[l - 1]))