import numpy as np

def isprime(x):

  if x<=1:return False

  if x==2:return True

  for i in range(2,int(x**0.5)+1):

    if x%i==0:return False

  return True



#リスト作成

prime=[isprime(i) for i in range(10**5+1)]



def like2017(x):

  return (prime[x] and prime[(x+1)//2])



a=[like2017(i) for i in range(10**5+1)]



ac=np.cumsum(a)



q=int(eval(input()))

for i in range(q):

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

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

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]))

import numpy as np


def isprime(x):
    if x <= 1:
        return False
    if x == 2:
        return True
    for i in range(2, int(x**0.5) + 1):
        if x % i == 0:
            return False
    return True


# リスト作成
prime = [isprime(i) for i in range(10**5 + 1)]


def like2017(x):
    return prime[x] and prime[(x + 1) // 2]


a = [like2017(i) for i in range(10**5 + 1)]
ac = np.cumsum(a)
q = int(eval(input()))
for i in range(q):
    l, r = list(map(int, input().split()))
    print((ac[r] - ac[l - 1]))

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]))

- -def isprime(x): -    if x <= 1: -        return False -    if x == 2: -        return True -    for i in range(2, int(x**0.5) + 1): -        if x % i == 0: -            return False -    return True - - -# リスト作成 -prime = [isprime(i) for i in range(10**5 + 1)] - - -def like2017(x): -    return prime[x] and prime[(x + 1) // 2] - - -a = [like2017(i) for i in range(10**5 + 1)] -ac = np.cumsum(a) +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() -    print((ac[r] - ac[l - 1])) +    print((like2017_cumsum[r] - like2017_cumsum[l - 1]))