fibonacci_large.cpp File Reference

Computes N^th Fibonacci number given as input argument. Uses custom build arbitrary integers library to perform additions and other operations. More...

`#include <cinttypes>`
`#include <ctime>`
`#include <iostream>`
`#include "./large_number.h"`
Include dependency graph for fibonacci_large.cpp:

## Functions

large_number | fib (uint64_t n)
int | main (int argc, char *argv[])

## Detailed Description

Computes N^th Fibonacci number given as input argument. Uses custom build arbitrary integers library to perform additions and other operations.

Took 0.608246 seconds to compute 50,000^th Fibonacci number that contains 10450 digits!

Author
  Krishna Vedala

See also
  fibonacci.cpp, fibonacci_fast.cpp, string_fibonacci.cpp

## Function Documentation

## fib()

large_number fib | ( | uint64_t | n | ) |

Compute fibonacci numbers using the relation

\[f(n)=f(n-1)+f(n-2)\]

and returns the result as a large_number type.

{
large_number f0(1);
large_number f1(1);
do {
large_number f2 = f1;
f1 += f0;
f0 = f2;
n--;
} while (n > 2); // since we start from 2
return f1;
}
large_number
Definition: large_number.h:24