[url]http://acm.hdu.edu.cn/showproblem.php?pid=2136[/url]
[size=medium]题意:求出n的最大素数因子的位置
[color=blue]Sample Input
1
2
3
4
5
Sample Output
0
1
2
1
3[/color][/size]
[size=medium]题意:求出n的最大素数因子的位置
[color=blue]Sample Input
1
2
3
4
5
Sample Output
0
1
2
1
3[/color][/size]
#include <iostream>
using namespace std;
#define maxs 1000001
bool prime[maxs];
int res[maxs]; //res[j]存放j的最大素数因子的位置,即答案
int main()
{
int i, j, count = 1; //count初始化为1,位置
for (i = 2; i < maxs; i++)
{
if (!prime[i])
{
res[i] = count; //素数i的位置
for (j = i << 1; j < maxs; j += i) //构造出j的暂时最大素数因子的位置
prime[j] = true, res[j] = count;//因为j明显是i的倍数 Orz...
count++;
}
}
while (scanf ("%d", &j) != EOF)
printf ("%d\n", res[j]);
return 0;
}