Everybody knows any number can be combined by the prime number.
Now, your task is telling me what position of the largest prime factor.
The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc.
Specially, LPF(1) = 0.
筛出来放在表里直接输出
#include <cstdio>
const int MAX=1000000;
int prime[MAX]={0};
int mark[MAX]={0};
void init()
{
for(int i=2,n=1;i<MAX;i++)
{
if(prime[i]==0)
{
mark[i]=n++;
for(int j=i;j<MAX;j=j+i)
{
prime[j]=i; //筛掉i的倍数
}
}
}
}
int main()
{
int n;
init();
while(~scanf("%d",&n))
{
printf("%d\n",mark[prime[n]]); //prime中存放这个数的最大质因数
}
return 0;
}