Euler 1-5

This commit is contained in:
Jos van Goor 2022-12-01 16:45:37 +01:00
parent 9cf858b860
commit 68a75987e2
6 changed files with 161 additions and 0 deletions

31
project_euler/problem2.cc Normal file
View file

@ -0,0 +1,31 @@
#include <cstdint>
#include <fmt/format.h>
std::int64_t fibonacci()
{
static std::int64_t first = 1;
static std::int64_t second = 2;
std::int64_t result = first + second;
std::swap(first, second);
second = result;
return result;
}
int main()
{
std::int64_t result = 2;
while (true)
{
std::int64_t value = fibonacci();
if (value >= 4'000'000)
break;
if (value % 2 == 0)
result += value;
}
fmt::print("Result: {}\n", result);
}