Problem 10 2000000以下素数和

http://projecteuler.net/problem=10


#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 2000000;
bool prime[MAXN + 10] = {1,1,0};
int main()
{
	int i;
	int j;
	int ans = 0;
	long long lans = 0;
	for(i = 2; i <= MAXN; i++)
	{
		if(prime[i] == 0)
		{
	//		getchar();
			printf("%d   ",i);
			ans += i;
			lans += i;

			for(j = i + i; j <= MAXN; j = j + i)
			{
				if(prime[j] == 0)
				{
					prime[j] = 1;
				}
			}
		}
	}
	printf("%lld\n",lans);
	printf("%d\n",ans);

	return 0;
}


你可能感兴趣的:(Problem 10 2000000以下素数和)