【Project Euler】【Problem 10】Summation of primes

Summation of primes

Problem 10

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.


Answer:
142913828922
翻译

质数的和

问题 10

10以内所有质数的和是: 2 + 3 + 5 + 7 = 17.

求2000000以内所有质数的和。


答案:
142913828922
解法一:
#include 
#include 

bool isPrime(long num)
{
    int _sqrt = (long)sqrt(num);

    if (num == 2 || num == 3)
    {
        return true;
    }

    for (int i = 2; i <= _sqrt; i++ )
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}


int main(int argc, char *argv[])
{
	long long result = 0;
	long maxNum = 2000000;
	int _count = 1;
	for (long i = 2; i


你可能感兴趣的:(C,Project,Euler)