In many programming competitions, we are asked to find (or count the number of) Prime Factors of an integer i. This is boring. This time, let’s count the number of Non-Prime Factors of an integer i
, denoted as NPF(i).
For example, integer 100
has the following nine factors: {1,2⎯⎯,4,5⎯⎯,10,20,25,50,100}. The two which are underlined are prime factors of 100 and the rest are non-prime factors. Therefore, NPF(100) = 7
.
Input
The first line contains an integer Q
(1≤Q≤3⋅106) denoting the number of queries. Each of the next Q lines contains one integer i (2≤i≤2⋅106
).
Output
For each query i
, print the value of NPF(i).
Warning
The I/O files are large. Please use fast I/O methods.
Sample Input 1 Sample Output 1
4
100
13
12
2018
7
1
4
2
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define maxx 2e6+5
int vis[2000002];
int ans[2000002];
void f()
{
vis[1]=1;
for(int i=2; i<=sqrt(maxx); ++i)
{
if(!vis[i])
{
for(int j=i*i; j<=2000002; j+=i)
{
vis[j]=1;
}
}
}
for(int i = 1; i <= 2000000; ++i)
{
int rt = 2000000/i;
for(int j = i; j <= rt; ++j)
{
if(vis[i])
{
ans[i*j]++;
}
if(vis[j] && i!=j)
{
ans[i*j]++;
}
}
}
}
int main()
{
int t;
f();
scanf("%d", &t);
while(t--)
{
int n;
scanf("%d", &n);
printf("%d\n", ans[n]);
}
return 0;
}