give you a number, ask you to find the number of the largest prime factor in the list of prime numbers position.
largest prime factor Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
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.
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
Author Wiskey
Source HDU 2007-11 Programming Contest_warmup
#include <stdio.h>
#include <string.h>
#define MAXN 1000000+1000
int PRIME[MAXN];
int main ()
{
int k=1;//initialization k is positioned as 1
int i,j,n;
memset (prime,0,sizeof (prime));
/* Filter location/for
(i=2;i<maxn;i++)//To MAXN, not sqrt (MAXN)
{
if (!prime[i))//if (prime[i]==0)
{ Position
of the prime[i]=k;//prime number I for
(j=i+i;j<maxn;j+=i)
{
prime[j]=k;//constructs the position of the temporary maximum prime number factor of J
}
k++
}
}
while (~SCANF ("%d", &n))
{
printf ("%d\n", Prime[n]);
return 0;
}