Description
Everybody 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.
Input
Each line would 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
#include <iostream> #include <cstdio> #include <cstring> #include <
Algorithm> #include <cmath> using namespace std;
int prime[1000001];
BOOL isprime[1000001];
int p;
struct node//completely can not use, just lazy don't want to change {int pos;} pp[1000009];
void sieve () {int i,j;
memset (isprime,true,sizeof (IsPrime));
Isprime[0]=isprime[1]=false;
for (i=2; i<=1000001; i++) {if (Isprime[i]) {pp[i].pos=p;
Prime[p++]=i; The maximum prime factor for the for (j=2*i; j<=1000000; j+=i) {pp[j].pos=pp[i].pos;//j is I isprime[j]
=false;
}}} Isprime[1]=true;
} int main () {int n;
P=1;
Prime[0]=1;
Sieve ();
pp[1].pos=0;
while (scanf ("%d", &n)!=eof) {printf ("%d\n", Pp[n].pos);
} return 0; }