-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path10539 - Almost Prime Numbers.cpp
74 lines (67 loc) · 1.43 KB
/
10539 - Almost Prime Numbers.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<stdio.h>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#define sz 1000001
using namespace std;
vector<int>prime;
vector<long long int>ans;
bool flag[1000001];
int prsz;
void sieve(void)
{
int i,j,add;
flag[0]=flag[1]=1;
prime.push_back(2);
for(i=4; i<sz; i+=2)
flag[i]=1;
for(i=3; i<sz; i+=2)
{
if(!flag[i])
{
prime.push_back(i);
if(sz/i>=i)
{
add=i*2;
for(j=i*i; j<sz; j+=add)
flag[j]=1;
}
}
}
}
int main()
{
sieve();
long long int i,k,szp,j;
szp=prime.size();
// printf("total prime %lld\n",szp);
// for(i=0; i<=20; i++)
// printf("%d ",prime[prime.size()-1]);
// printf("\n\n\n");
for(i=0; i<sz; i++)
{
if(!flag[i])
for(j=i*i; j<1000000000001; j*=i)
ans.push_back(j);
// for(j=prime[i]*prime[i];j<1000000000001;j*=prime[i])
// ans.push_back(j); //does not work :( ;(
}
sort(ans.begin(),ans.end());
int tst,count,ansz;
ansz=ans.size();
// printf("total ans %d\n",ansz);
long long x,y;
scanf("%d",&tst);
while(tst--)
{
count=0;
scanf("%lld %lld",&x,&y);
i=0;
while(ans[i]<x)i++;
for(; i<ansz && ans[i]<=y; i++)
count++;
printf("%d\n",count);
}
return 0;
}