C++ Implementation of Problem 10

View source code here on GitHub!

Includes

Solution

uint64_t p0010()
int main(int argc, char const *argv[])

Note

This function is only present in the Python test runner, or when compiling as a standalone program.

 1/*
 2Project Euler Problem 10
 3
 4Problem:
 5
 6The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
 7
 8Find the sum of all the primes below two million.
 9*/
10#ifndef EULER_P0010
11#define EULER_P0010
12#include <stdint.h>
13#include <iostream>
14#include "include/macros.hpp"
15#include "include/primes.hpp"
16
17uint64_t EMSCRIPTEN_KEEPALIVE p0010() {
18    uint64_t tmp, answer = 0;
19    PrimeGenerator<uint64_t> pg = primes<uint64_t>();
20    while ((tmp = pg.next()) < 2000000)
21        answer += tmp;
22    return answer;
23}
24
25PROGRAM_TAIL(p0010)
26#endif

Tags: cpp-iterator, prime-number