Advertisement

Non-Prime Factors(素数筛 + 质因分解)

阅读量:

Within numerous programming contests, participants are typically required to identify (or enumerate) the Prime Factors associated with a given integer ii. This task is rather monotonous. Conversely, this iteration involves counting the Non-Prime Factors composing a specific integer ii and representing this quantity as NPF(i).

For instance, number 1₀₀₁₀₀ is characterized by nine factors: {1,,2,,,4,,5,,, etc.} The specific elements highlighted correspond to its prime factorization while the others represent composite factorization. Consequently,NPF(₁₀₀) equals ₇₇.

Input

The first line includes an integer value QQ, where 1 ≤ Q ≤ 3×10^6, representing the number of queries. For each subsequent line in these QQ lines, there is an integer ii (where 2 ≤ i ≤ 2×10^6) present.

Output

For each query ii, 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;
    
 }

全部评论 (0)

还没有任何评论哟~