Largest prime factor

#include <iostream>
#define max 1000001
int prime[max];
int main()
{
    int i,j,n=0;
    memset(prime,-1,sizeof(prime));
    prime[1]=0;
    for(i=2;i<max;i++)
    {
        if(prime[i]==-1)
        {
            n++;
            for(j=i;j<max;j+=i)
                prime[j]=n;
        }
    }
    while(~scanf("%d",&n))
    {
        printf("%d\n",prime[n]);
    }
    return 0;
}

 

posted @ 2013-09-19 15:13  Destino74  阅读(51)  评论(0编辑  收藏  举报