largest prime factor
Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 9962 accepted Submission (s): 3514
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
AC Code:
#include <iostream>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
typedef long LL;
using namespace std;
Const LL MAXN=1E6;
Const LL mod=10000000;
int a[maxn]={0};
Prime number filter: Hit the table
int main ()
{
int n,k=1;
for (int i=2;i<maxn;i++)
{
if (a[i]==0)
{
a[i]=k++,//position for
(int j=i+i;j<maxn; J+=i)
{
a[j]=a[i];
}} while (~SCANF ("%d", &n))
{
if (n==1) printf ("0\n");
else
cout<<a[n]<<endl;
}
return 0;
}