max_num = 10**5+5

eratos_thenes_sieve = [0,0] + [1]*max_num

n = 2 #素数

while n*n <= max_num:

  if eratos_thenes_sieve[n]:#

    for i in range(2*n, max_num, n):

      eratos_thenes_sieve[i] = 0

  n += 1

  

isLike2017 = [0] * max_num

cumulativeSums = [0]

for i in range(max_num):

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

    isLike2017[i] = 1

  cumulativeSums.append(cumulativeSums[-1] + isLike2017[i])

  

  

q = int(eval(input()))



for i in range(q):

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

  print((cumulativeSums[r+1] - cumulativeSums[l]))
Q = int(eval(input()))

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





N = 10**5

is_prime = [True] * (N+1)

is_prime[0] = False

is_prime[1] = False

for i in range(2,N+1):

    if is_prime[i]:

        j = 2

        while j * i <= N:

            is_prime[i*j] = False

            j += 1



cum_like2017 = [0] * (N+1)

for i in range(1,N+1):

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

        cum_like2017[i] = cum_like2017[i-1] + 1

    else:

        cum_like2017[i] = cum_like2017[i-1] 





for l, r in lr:

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

max_num = 10**5 + 5
eratos_thenes_sieve = [0, 0] + [1] * max_num
n = 2  # 素数
while n * n <= max_num:
    if eratos_thenes_sieve[n]:  #
        for i in range(2 * n, max_num, n):
            eratos_thenes_sieve[i] = 0
    n += 1
isLike2017 = [0] * max_num
cumulativeSums = [0]
for i in range(max_num):
    if eratos_thenes_sieve[i] and eratos_thenes_sieve[(i + 1) // 2]:
        isLike2017[i] = 1
    cumulativeSums.append(cumulativeSums[-1] + isLike2017[i])
q = int(eval(input()))
for i in range(q):
    l, r = list(map(int, input().split()))
    print((cumulativeSums[r + 1] - cumulativeSums[l]))

Q = int(eval(input()))
lr = [tuple(map(int, input().split())) for _ in range(Q)]
N = 10**5
is_prime = [True] * (N + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, N + 1):
    if is_prime[i]:
        j = 2
        while j * i <= N:
            is_prime[i * j] = False
            j += 1
cum_like2017 = [0] * (N + 1)
for i in range(1, N + 1):
    if is_prime[i] and is_prime[(i + 1) // 2]:
        cum_like2017[i] = cum_like2017[i - 1] + 1
    else:
        cum_like2017[i] = cum_like2017[i - 1]
for l, r in lr:
    print((cum_like2017[r] - cum_like2017[l - 1]))

-max_num = 10**5 + 5 -eratos_thenes_sieve = [0, 0] + [1] * max_num -n = 2  # 素数 -while n * n <= max_num: -    if eratos_thenes_sieve[n]:  # -        for i in range(2 * n, max_num, n): -            eratos_thenes_sieve[i] = 0 -    n += 1 -isLike2017 = [0] * max_num -cumulativeSums = [0] -for i in range(max_num): -    if eratos_thenes_sieve[i] and eratos_thenes_sieve[(i + 1) // 2]: -        isLike2017[i] = 1 -    cumulativeSums.append(cumulativeSums[-1] + isLike2017[i]) -q = int(eval(input())) -for i in range(q): -    l, r = list(map(int, input().split())) -    print((cumulativeSums[r + 1] - cumulativeSums[l])) +Q = int(eval(input())) +lr = [tuple(map(int, input().split())) for _ in range(Q)] +N = 10**5 +is_prime = [True] * (N + 1) +is_prime[0] = False +is_prime[1] = False +for i in range(2, N + 1): +    if is_prime[i]: +        j = 2 +        while j * i <= N: +            is_prime[i * j] = False +            j += 1 +cum_like2017 = [0] * (N + 1) +for i in range(1, N + 1): +    if is_prime[i] and is_prime[(i + 1) // 2]: +        cum_like2017[i] = cum_like2017[i - 1] + 1 +    else: +        cum_like2017[i] = cum_like2017[i - 1] +for l, r in lr: +    print((cum_like2017[r] - cum_like2017[l - 1]))