C++ Implementation of Problem 7

View source code here on GitHub!

Includes

Solution

uint32_t p0007()
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 7
 3
 4The prime number infrastructure paid off here
 5
 6Problem:
 7
 8By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
 9
10What is the 10 001st prime number?
11*/
12
13#ifndef EULER_P0007
14#define EULER_P0007
15#include <stdint.h>
16#include <iostream>
17#include "include/macros.hpp"
18#include "include/primes.hpp"
19
20uint32_t EMSCRIPTEN_KEEPALIVE p0007() {
21    uint32_t answer, count = 0;
22    PrimeGenerator<uint32_t> ps = primes<uint32_t>();
23    while (true) {
24        answer = ps.next();
25        if (++count == 10001)
26            break;
27    }
28    return answer;
29}
30
31PROGRAM_TAIL(p0007)
32#endif

Tags: cpp-iterator, prime-number