import numpy as np

MAX_N=10**5

prime=np.full(MAX_N+1,True)

prime[:2]=False #0,1をFalseにしてる

for p in range(2,int(MAX_N**.5)+1):

  if prime[p]:

    prime[p*p::p]=False #p:素数の倍数をFalseに変える



like2017=np.zeros(MAX_N+1,dtype=np.int64)

for p in range(1,MAX_N+1):

  if 2*p>MAX_N:  #(p+1)//2をpとよみかえると、pと2*p-1になる

    break

  if prime[p] and prime[2*p-1]:

    like2017[2*p-1]=1



like2017_cumsum=like2017.cumsum()



q=int(eval(input()))

for i in range(q):

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

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

U=10**5

is_prime=[True]*(U+1)

is_prime[0]=False

is_prime[1]=False

for p in range(2,U+1):

    if p*p>U:

        break

    if is_prime[p]:

        for j in range(p*p,U+1,p):

            is_prime[j]=False



is_2017like=[0]*(U+1)

for p in range(1,U+1):

    if (p+1)//2>U:

        break

    tmp=(is_prime[p] and is_prime[(p+1)//2])

    is_2017like[p]=is_2017like[p-1]+tmp

    

for i in range(int(eval(input()))):

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

    ans=is_2017like[r]-is_2017like[l-1]

    print(ans)

import numpy as np

MAX_N = 10**5
prime = np.full(MAX_N + 1, True)
prime[:2] = False  # 0,1をFalseにしてる
for p in range(2, int(MAX_N**0.5) + 1):
    if prime[p]:
        prime[p * p :: p] = False  # p:素数の倍数をFalseに変える
like2017 = np.zeros(MAX_N + 1, dtype=np.int64)
for p in range(1, MAX_N + 1):
    if 2 * p > MAX_N:  # (p+1)//2をpとよみかえると、pと2*p-1になる
        break
    if prime[p] and prime[2 * p - 1]:
        like2017[2 * p - 1] = 1
like2017_cumsum = like2017.cumsum()
q = int(eval(input()))
for i in range(q):
    l, r = list(map(int, input().split()))
    print((like2017_cumsum[r] - like2017_cumsum[l - 1]))

U = 10**5
is_prime = [True] * (U + 1)
is_prime[0] = False
is_prime[1] = False
for p in range(2, U + 1):
    if p * p > U:
        break
    if is_prime[p]:
        for j in range(p * p, U + 1, p):
            is_prime[j] = False
is_2017like = [0] * (U + 1)
for p in range(1, U + 1):
    if (p + 1) // 2 > U:
        break
    tmp = is_prime[p] and is_prime[(p + 1) // 2]
    is_2017like[p] = is_2017like[p - 1] + tmp
for i in range(int(eval(input()))):
    l, r = list(map(int, input().split()))
    ans = is_2017like[r] - is_2017like[l - 1]
    print(ans)

-import numpy as np - -MAX_N = 10**5 -prime = np.full(MAX_N + 1, True) -prime[:2] = False  # 0,1をFalseにしてる -for p in range(2, int(MAX_N**0.5) + 1): -    if prime[p]: -        prime[p * p :: p] = False  # p:素数の倍数をFalseに変える -like2017 = np.zeros(MAX_N + 1, dtype=np.int64) -for p in range(1, MAX_N + 1): -    if 2 * p > MAX_N:  # (p+1)//2をpとよみかえると、pと2*p-1になる +U = 10**5 +is_prime = [True] * (U + 1) +is_prime[0] = False +is_prime[1] = False +for p in range(2, U + 1): +    if p * p > U: -    if prime[p] and prime[2 * p - 1]: -        like2017[2 * p - 1] = 1 -like2017_cumsum = like2017.cumsum() -q = int(eval(input())) -for i in range(q): +    if is_prime[p]: +        for j in range(p * p, U + 1, p): +            is_prime[j] = False +is_2017like = [0] * (U + 1) +for p in range(1, U + 1): +    if (p + 1) // 2 > U: +        break +    tmp = is_prime[p] and is_prime[(p + 1) // 2] +    is_2017like[p] = is_2017like[p - 1] + tmp +for i in range(int(eval(input()))): -    print((like2017_cumsum[r] - like2017_cumsum[l - 1])) +    ans = is_2017like[r] - is_2017like[l - 1] +    print(ans)