mirror of
https://github.com/lucaspalomodevelop/cpp_stuff.git
synced 2026-03-12 22:47:22 +00:00
add fast fib
This commit is contained in:
parent
1727156974
commit
8e48d9bf91
BIN
fibonacci_fast/fib
Executable file
BIN
fibonacci_fast/fib
Executable file
Binary file not shown.
19
fibonacci_fast/main.cpp
Normal file
19
fibonacci_fast/main.cpp
Normal 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
5
fibonacci_fast/makefile
Normal file
@ -0,0 +1,5 @@
|
||||
dev: compile run
|
||||
compile:
|
||||
g++ -o fib main.cpp
|
||||
run:
|
||||
./fib
|
||||
Loading…
x
Reference in New Issue
Block a user