forked from Vicky-Jha/Number-Theory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicroPrimePrime.cpp
More file actions
36 lines (34 loc) · 777 Bytes
/
Copy pathmicroPrimePrime.cpp
File metadata and controls
36 lines (34 loc) · 777 Bytes
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
#include <bits/stdc++.h>
#define MAX 1000000
using namespace std;
vector<int> countPrime(MAX+1,0);
vector<bool> isPrime(MAX+1,1);
void seive()
{
isPrime[0] = 0;
isPrime[1] = 0;
for(int i=2 ; i*i<=MAX ; ++i)
if(isPrime[i])
for(int j=i*i ; j<=MAX ; j += i)
isPrime[j] = 0;
for(int i = 1 ; i<=MAX ; ++i)
countPrime[i] = + countPrime[i-1] + isPrime[i];
}
int main()
{
seive();
int t , l ,r ;
cin>>t;
while(t--)
{
cin>>l>>r;
int c=0;
for(int i=l ; i<=r ; ++i)
if(isPrime[countPrime[i]]){
c++;
// cout<<isPrime[countPrime[i]]<<" "<<countPrime[i] << " "<<i<<"\n";
}
cout<<c<<"\n";
}
return 0;
}