-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.py
50 lines (40 loc) · 979 Bytes
/
D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
def seachPrimeNum(N):
max = int(np.sqrt(N))
seachList = [i for i in range(2,N+1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
q = int(input())
lr =[]
MAX = 0
for i in range(q):
l, r = map(int, input().split())
lr.append([l, r])
MAX = max(MAX, r)
primes = seachPrimeNum(int(MAX))
l = len(primes)
dic = {}
for i in primes:
dic[i] = True
co_primes = []
for i in range(l):
if dic.get((primes[i]+1)//2):
co_primes.append(primes[i])
prime_for_lr = []
max_l = len(co_primes)
now = 0
for i in range(MAX+1):
if now >= max_l:
prime_for_lr.append(now)
elif i<co_primes[now]:
prime_for_lr.append(now)
else:
now += 1
prime_for_lr.append(now)
for l, r in lr:
print(prime_for_lr[r]-prime_for_lr[l-1])