-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp10.cpp
More file actions
32 lines (29 loc) · 745 Bytes
/
Copy pathp10.cpp
File metadata and controls
32 lines (29 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
*
* Find the sum of all the primes below two million.
*/
#include <cstdint>
#include <iostream>
#include <numeric>
#include "euler/prime_table.hpp"
#include "euler.h"
BEGIN_PROBLEM(10, solve_problem_10)
PROBLEM_TITLE("Calculate the sum of all the primes below 2,000,000")
PROBLEM_ANSWER("142913828922")
PROBLEM_DIFFICULTY(1)
PROBLEM_FUN_LEVEL(1)
PROBLEM_TIME_COMPLEXITY("N*ln(ln(N))")
PROBLEM_SPACE_COMPLEXITY("N")
END_PROBLEM()
static void solve_problem_10()
{
#if 0
const int n = 10;
#else
const int n = 2000000;
#endif
euler::prime_table<int> primes(n);
int64_t sum = std::accumulate(primes.begin(), primes.end(), 0LL);
std::cout << sum << std::endl;
}