Largest prime factor
Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 9993 Accepted Submission (s): 3528
Problem Descriptioneverybody knows any number can is combined by the prime number.
Now, your task was telling me what position of the largest prime factor.
The position of Prime 2 is 1, Prime 3 are 2, and Prime 5 is 3, etc.
Specially, LPF (1) = 0.
Inputeach line would contain one integer n (0 < n < 1000000).
Outputoutput the LPF (n).
Sample Input12345
Sample Output01213
#include <stdio.h>#include<math.h>#include<iostream>#include<algorithm>#include<string.h>#include<stdlib.h>using namespaceStd;typedefLong LongLL;Const intN =1000000;BOOLP[n];///to False represents a prime numberintIdx[n];voidinit () {memset (P,false,sizeof(p)); intID =1; for(intI=2; i<n;i++){ if(!P[i]) {Idx[i]= id++; for(ll j= (LL) i*i;j<n;j+=i) {P[j]=true; } } }}intGetmax (intN) { intMax =-1; for(intI=2; i*i<=n;i++){ if(n%i==0){ while(n%i==0) {n/=i; } Max=Max (I,max); } } if(n>1) Max =Max (max,n); returnMax;}intMain () {init (); intN; while(SCANF ("%d", &n)! =EOF) { if(n==1) printf ("0\n"); Else{ intMax =Getmax (n); printf ("%d\n", Idx[max]); } }}
HDU 2136 (Prime number filter + integer decomposition)