POJ 3292 Semi-prime H-numbers (筛半H-素数)

http://poj.org/problem?id=3292


/*47ms,4300KB*/

#include<cstdio>

int h[100005];

int main()
{
	int i, j;
	for (i = 5; i < 1000; i += 4)
		if (h[i] == 0)
			for (j = i; i * j < 1000002; j += 4)
				h[i * j] = h[i] + h[j] + 1;///筛半H-素数的技巧
	for (i = 25; i < 1000002; ++i)
		h[i] = (h[i] == 1) + h[i - 1];
	while (scanf("%d", &i), i)
		printf("%d %d\n", i, h[i]);
	return 0;
}

你可能感兴趣的:(C++,数论,ACM,poj)