HDU 2136 Largest prime factor

http://acm.hdu.edu.cn/showproblem.php?pid=2136

求n的最大素因子在素数表中的位置。如代码循环,因为如果在前面被计算过则肯定不是素数。

View Code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int rank[1100000];
int main()
{
int n,cnt=1;
for(int i=2;i<1000001;i++)
{
if(rank[i])continue;
for(int j=i;j<1000001;j+=i)
rank[j]=cnt;
cnt++;
}
while(~scanf("%d",&n))
printf("%d\n",rank[n]);
return 0;
}
原文地址:https://www.cnblogs.com/xiaohongmao/p/2437483.html