add fast fib

This commit is contained in:
lucaspalomodevelop 2022-11-03 17:37:17 +01:00
parent 1727156974
commit 8e48d9bf91
3 changed files with 24 additions and 0 deletions

BIN
fibonacci_fast/fib Executable file

Binary file not shown.

19
fibonacci_fast/main.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<iostream>
#include <map>
uint64_t fib(uint64_t n)
{
static std::map<uint64_t,uint64_t> table{};
table[n] = n < 2 ? 1 : table[n-2] + table[n-1];
return table[n];
}
int main()
{
std::cout << "Geben sie an die wievielte fib. Zahl sie suchen: ";
std::uint64_t n = 0;
std::cin >> n;
for(uint64_t i = 0; i <= n; ++i)
{
std::cout << "fib("<< i-1 <<") = " << fib(i) << "\n";
}
}

5
fibonacci_fast/makefile Normal file
View File

@ -0,0 +1,5 @@
dev: compile run
compile:
g++ -o fib main.cpp
run:
./fib