TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
An algorithm to calculate the sum of Fibonacci Sequence: \(\mathrm{F}(n) + \mathrm{F}(n+1) + .. + \mathrm{F}(m)\). More...
#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | math |
for assert | |
namespace | fibonacci_sum |
Functions for the sum of the Fibonacci Sequence: \(\mathrm{F}(n) +
\mathrm{F}(n+1) + .. + \mathrm{F}(m)\). | |
Typedefs | |
using | math::fibonacci_sum::matrix = std::vector<std::vector<uint64_t> > |
Functions | |
math::fibonacci_sum::matrix | math::fibonacci_sum::multiply (const math::fibonacci_sum::matrix &T, const math::fibonacci_sum::matrix &A) |
math::fibonacci_sum::matrix | math::fibonacci_sum::power (math::fibonacci_sum::matrix T, uint64_t ex) |
uint64_t | math::fibonacci_sum::result (uint64_t n) |
uint64_t | math::fibonacci_sum::fiboSum (uint64_t n, uint64_t m) |
static void | test () |
int | main () |
Main function. | |
An algorithm to calculate the sum of Fibonacci Sequence: \(\mathrm{F}(n) + \mathrm{F}(n+1) + .. + \mathrm{F}(m)\).
An algorithm to calculate the sum of Fibonacci Sequence: \(\mathrm{F}(n) + \mathrm{F}(n+1) + .. + \mathrm{F}(m)\) where \(\mathrm{F}(i)\) denotes the i-th Fibonacci Number . Note that F(0) = 0 and F(1) = 1. The value of the sum is calculated using matrix exponentiation. Reference source: https://stackoverflow.com/questions/4357223/finding-the-sum-of-fibonacci-numbers
Definition in file fibonacci_sum.cpp.
using math::fibonacci_sum::matrix = std::vector<std::vector<uint64_t> > |
Definition at line 31 of file fibonacci_sum.cpp.
uint64_t math::fibonacci_sum::fiboSum | ( | uint64_t | n, |
uint64_t | m ) |
Function to compute sum of fibonacci sequence from n to m.
n | start of sequence |
m | end of sequence |
Definition at line 91 of file fibonacci_sum.cpp.
int main | ( | void | ) |
Main function.
Definition at line 137 of file fibonacci_sum.cpp.
math::fibonacci_sum::matrix math::fibonacci_sum::multiply | ( | const math::fibonacci_sum::matrix & | T, |
const math::fibonacci_sum::matrix & | A ) |
Function to multiply two matrices
T | matrix 1 |
A | martix 2 |
Definition at line 39 of file fibonacci_sum.cpp.
math::fibonacci_sum::matrix math::fibonacci_sum::power | ( | math::fibonacci_sum::matrix | T, |
uint64_t | ex ) |
Function to compute A^n where A is a matrix.
T | matrix |
ex | power |
Definition at line 58 of file fibonacci_sum.cpp.
uint64_t math::fibonacci_sum::result | ( | uint64_t | n | ) |
Function to compute sum of fibonacci sequence from 0 to n.
n | number |
Definition at line 77 of file fibonacci_sum.cpp.
|
static |
Function for testing fiboSum function. test cases and assert statement.
void
Definition at line 102 of file fibonacci_sum.cpp.