1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5         const int max = 1000001;
 6         int *lpf = new int[max];
 7         int c = 2,n;
 8         for(int i = 0;i < max;++i) lpf[i] = 0;
 9         lpf[2] = 1;
10         for(int i = 4;i < max;i += 2)
11         {
12                 lpf[i] = lpf[2];
13         }
14         for(int i = 3;i < max;++i)
15         {
16                 if(lpf[i]) continue;
17                 lpf[i] = c++;
18                 for(int j = (i<<1);j < max;j += i)
19                 {
20                         lpf[j] = lpf[i];
21                 }
22         }
23         while(scanf("%d",&n) != EOF)
24                 printf("%d\n",lpf[n]);
25 
26         return 0;
27 }

 

相关文章:

  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-04-20
  • 2021-06-21
  • 2022-02-12
  • 2022-02-21
猜你喜欢
  • 2021-06-27
  • 2022-03-11
  • 2021-11-04
  • 2022-12-23
  • 2021-07-31
  • 2021-10-31
相关资源
相似解决方案