C++ Implementation of Problem 3

View source code here on GitHub!

Includes

Solution

uint16_t p0003()
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 3
 3
 4More lazy functions this time.
 5
 6Problem:
 7
 8The prime factors of 13195 are 5, 7, 13 and 29.
 9
10What is the largest prime factor of the number 600851475143 ?
11*/
12
13#ifndef EULER_P0003
14#define EULER_P0003
15#include <stdint.h>
16#include <iostream>
17#include "include/macros.hpp"
18#include "include/primes.hpp"
19
20uint16_t EMSCRIPTEN_KEEPALIVE p0003() {
21    uint16_t answer = 0;
22    PrimeFactors<uint64_t> pfs = prime_factors<uint64_t>(600851475143);
23    while (pfs.has_next())
24        answer = (uint16_t) pfs.next();
25    return answer;
26}
27
28
29PROGRAM_TAIL(p0003)
30#endif

Tags: cpp-iterator, factorization, prime-number