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 }