C++ Implementation of Problem 1
View source code here on GitHub!
Includes
Solution
-
uint64_t p0001()
-
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/**
2 * Project Euler Problem 1
3 *
4 * I did this the traditional way in C++, mostly because I want to see if there
5 * is a way to do iteration in native C++ before hacking together a solution just
6 * because I can.
7 *
8 * Problem:
9 *
10 * If we list all the natural numbers below 10 that are multiples of 3 or 5, we
11 * get 3, 5, 6 and 9. The sum of these multiples is 23.
12 *
13 * Find the sum of all the multiples of 3 or 5 below 1000.
14 */
15#ifndef EULER_P0001
16#define EULER_P0001
17#include <stdint.h>
18#include <iostream>
19#include "include/macros.hpp"
20
21uint64_t EMSCRIPTEN_KEEPALIVE p0001() {
22 uint64_t answer = 0;
23 for (int i = 0; i < 1000; i += 3)
24 answer += i;
25 for (int i = 0; i < 1000; i += 5)
26 answer += i;
27 for (int i = 0; i < 1000; i += 15)
28 answer -= i;
29 return answer;
30}
31
32
33PROGRAM_TAIL(p0001)
34#endif