import numpy as np

Q = int(eval(input()))

lr = [list(map(int, input().split())) for _ in range(Q)]



is_prime = np.zeros(10**5 + 1, dtype='bool')

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

    if not is_prime[i]:

        for j in range(2, int(np.sqrt(i) + 1)):

            if i % j == 0:

                break

        else:

            is_prime[i] = True

            # is_prime[::i] = True

# print(is_prime[:10])



like_2017 = np.zeros(10**5 + 1, dtype='bool')

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

    if is_prime[i] and is_prime[(i + 1) // 2]:

        like_2017[i] = True

# print(like_2017)

# print(like_2017.cumsum())

cumsum = like_2017.cumsum()



for l, r in lr:

    print((cumsum[r] - cumsum[l - 1]))

import numpy as np

Q = int(eval(input()))

lr = [list(map(int, input().split())) for _ in range(Q)]



U = 10**5 * 1

is_prime = np.ones(U, dtype='bool')

is_prime[0:2] = False

for i in range(2, U):

    if i * i > 10**5:

        break

    if is_prime[i]:

        is_prime[i * 2::i] = False



like_2017 = np.zeros(U, dtype='bool')

for i in range(1, U):

    if 2 * i > U:

        break

    if is_prime[i] and is_prime[i * 2 - 1]:

        like_2017[i * 2 - 1] = True

cumsum = like_2017.cumsum()



for l, r in lr:

    print((cumsum[r] - cumsum[l - 1]))

import numpy as np

Q = int(eval(input()))
lr = [list(map(int, input().split())) for _ in range(Q)]
is_prime = np.zeros(10**5 + 1, dtype="bool")
for i in range(2, 10**5 + 1):
    if not is_prime[i]:
        for j in range(2, int(np.sqrt(i) + 1)):
            if i % j == 0:
                break
        else:
            is_prime[i] = True
            # is_prime[::i] = True
# print(is_prime[:10])
like_2017 = np.zeros(10**5 + 1, dtype="bool")
for i in range(1, 10**5 + 1):
    if is_prime[i] and is_prime[(i + 1) // 2]:
        like_2017[i] = True
# print(like_2017)
# print(like_2017.cumsum())
cumsum = like_2017.cumsum()
for l, r in lr:
    print((cumsum[r] - cumsum[l - 1]))

import numpy as np

Q = int(eval(input()))
lr = [list(map(int, input().split())) for _ in range(Q)]
U = 10**5 * 1
is_prime = np.ones(U, dtype="bool")
is_prime[0:2] = False
for i in range(2, U):
    if i * i > 10**5:
        break
    if is_prime[i]:
        is_prime[i * 2 :: i] = False
like_2017 = np.zeros(U, dtype="bool")
for i in range(1, U):
    if 2 * i > U:
        break
    if is_prime[i] and is_prime[i * 2 - 1]:
        like_2017[i * 2 - 1] = True
cumsum = like_2017.cumsum()
for l, r in lr:
    print((cumsum[r] - cumsum[l - 1]))

-is_prime = np.zeros(10**5 + 1, dtype="bool") -for i in range(2, 10**5 + 1): -    if not is_prime[i]: -        for j in range(2, int(np.sqrt(i) + 1)): -            if i % j == 0: -                break -        else: -            is_prime[i] = True -            # is_prime[::i] = True -# print(is_prime[:10]) -like_2017 = np.zeros(10**5 + 1, dtype="bool") -for i in range(1, 10**5 + 1): -    if is_prime[i] and is_prime[(i + 1) // 2]: -        like_2017[i] = True -# print(like_2017) -# print(like_2017.cumsum()) +U = 10**5 * 1 +is_prime = np.ones(U, dtype="bool") +is_prime[0:2] = False +for i in range(2, U): +    if i * i > 10**5: +        break +    if is_prime[i]: +        is_prime[i * 2 :: i] = False +like_2017 = np.zeros(U, dtype="bool") +for i in range(1, U): +    if 2 * i > U: +        break +    if is_prime[i] and is_prime[i * 2 - 1]: +        like_2017[i * 2 - 1] = True