MAX = 10000
# prefix[i] is going to
# store count of primes
# till i (including i).
pt =[0]*(MAX + 1)
def abc():
prime = [1]*(MAX + 1)
p = 2
while(p * p <= MAX):
if (prime[p] == 1):
i = p * 2
while(i <= MAX):
prime[i] = 0
i += p
p+=1
for p in range(2,MAX+1):
pt[p] = pt[p - 1]
if (prime[p]==1):
pt[p]+=1
//@allcoding1
def query(a,b):
return pt[b]-pt[a-1]
n=int(input())
c=0
for i in range(n):
a,b=map(int,input().split())
abc()
c+=query(a,b)
mod=10**9+7
print(c%mod)
prime numbers in range[L,R]
All test cases passed
Telegram :- @allcoding1
# prefix[i] is going to
# store count of primes
# till i (including i).
pt =[0]*(MAX + 1)
def abc():
prime = [1]*(MAX + 1)
p = 2
while(p * p <= MAX):
if (prime[p] == 1):
i = p * 2
while(i <= MAX):
prime[i] = 0
i += p
p+=1
for p in range(2,MAX+1):
pt[p] = pt[p - 1]
if (prime[p]==1):
pt[p]+=1
//@allcoding1
def query(a,b):
return pt[b]-pt[a-1]
n=int(input())
c=0
for i in range(n):
a,b=map(int,input().split())
abc()
c+=query(a,b)
mod=10**9+7
print(c%mod)
prime numbers in range[L,R]
All test cases passed
Telegram :- @allcoding1
👍14😁4
👎9🎉4👏3👍1🥰1😢1