Problem Description
Everybody knows any number can be combined by the prime number.
Now, your task is telling me what position of the largest prime factor.
The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc.
Specially, LPF(1) = 0.
Now, your task is telling me what position of the largest prime factor.
The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc.
Specially, LPF(1) = 0.
Input
Each line will contain one integer n(0 < n < 1000000).
Output
Output the LPF(n).
Sample Input
1 2 3 4 5
Sample Output
0 1 2 1 3题意:最大因子的位置。思路见AC代码:#include<stdio.h> #include<math.h> #define N 1000010 int prime[N]; int main() { int s,i,n,j,k,num; prime[1]=0; num=0; for(i=2; i<N; i++) { //因为2和3都是素数,所以2的倍数,3的倍数就会更新 //4是2的倍数,perim[4]还是1... if(prime[i]==0) { num++; //遇到一个素数,顺序加一个...表明第几个素数因子 for(j=i; j<N; j=j+i) //更新 新出现素数的所有倍数...此时被更新的值就是此时最大的因子 prime[j]=num; } } while(scanf("%d",&n)!=EOF) { printf("%d\n",prime[n]);//只需输出,在上述步骤得到的prime[n]即可, } return 0; }