Problem DescriptionEverybody 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.
InputEach line will contain one integer n (0 <n <1000000 ).
OutputOutput the LPF (n ).
Sample Input
12345
Sample Output
01213 question: in the simplest form of a number, the maximum prime factor is located in all prime numbers, starting from 0. Analysis: All numbers can be expressed by multiples of prime numbers. The reason is that there are two types of numbers: prime numbers and non-prime numbers. If the prime number is not a prime number, it can be decomposed to obtain the simplest form, and the prime number cannot be decomposed. The simplest form is itself. To sum up, the factor in the simplest form of A number must be a prime number. Method 1:# Include
Int prim [1000005] = {0}; void init () {int k; prim [1] = 0; k = 1; for (int I = 2; I <1000000; I ++) if (prim [I] = 0) // I is a prime number {for (int j = I; j <1000000; j + = I) prim [j] = k; k ++ ;}} int main () {int n; init (); while (scanf ("% d", & n)> 0) printf ("% d \ n", prim [n]);}
Method 2:#include
int vist[1000005]={0},prim[1000005];void init(){ int k; prim[1]=1; prim[2]=2;k=3; for(int i=3;i<1000000;i+=2) if(vist[i]==0) { prim[i]=k; k++; for(int j=i; j<1000000; j+=i) if(vist[j]==0) vist[j]=1; }}int main(){ int n,posit; init(); while(scanf("%d",&n)>0) { posit=1; for(int i=2; ; i++) if(prim[n]==0) { if(prim[i]&&n%i==0)posit=i; while(n%i==0)n/=i; } else { if(n>posit)posit=n; break; } printf("%d\n",prim[posit]-1); }}