Finding out nth fibonacci number for very large 'n'
By : Ahmad Nazmi
Date : March 29 2020, 07:55 AM
To fix this issue You can use the matrix exponentiation method (linear recurrence method). You can find detailed explanation and procedure in this blog. Run time is O(log n). I don't think there is a better way of doing this.

Finding next fibonacci number
By : thomas.olsen86
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Using a loop you could store the values in an array that could stop immediately one key after finding the selected number in the previous keys value. code :
function getFib($n) {
$fib = array($n+1); // array to num + 1
$fib[0] = 0; $fib[1] = 1; // set initial array keys
$i;
for ($i=2;$i<=$n+1;$i++) {
$fib[$i] = $fib[$i1]+$fib[$i2];
if ($fib[$i] > $n) { // check if key > num
return $fib[$i];
}
}
if ($fib[$i1] < $n) { // check if key < num
return $fib[$i1] + $n;
}
if ($fib[$i] = $n1) { // check if key = num
return $fib[$i1] + $fib[$i2];
}
if ($fib[$i1] = 1) { // check if num = 1
return $n + $n;
}
}
$num = 13;
echo "next fibonacci number = " . getFib($num);

Finding the fibonacci number of large number
By : Rasika Solamans
Date : March 29 2020, 07:55 AM
this one helps. The values will overflow because Fibonacci numbers increase very rapidly. Even for the original fibonacci series (where f(0) = 0 and f(1) = 1), the value of f(90) is more than 20 digits long which cannot be stored in any primitive data type in C++. You should probably use modulus operator (since you mentioned it in your question) to keep values within range like this: code :
a[n] = (fibo_dynamic(x,y,n1,a) + fibo_dynamic(x,y,n2,a)) % MOD;
if a = b + c, then:
a % n = ((b % n) + (c % n)) % n
f(n) = f(n1) + f(n2) for n >= 2

Why is one of these two algorithms for finding the nth Fibonacci number more efficient?
By : user2681208
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The second implementation is using "memoizing" to remember previously calculated Fibonacci values. Consider that you're trying to calculate fib(5): You first have to calculate fib(4) and fib(3). fib(4) itself also requires you to calculate fib(3). In fact, for every Fibonacci number, you can either calculate each of the preceding Fibonacci numbers once and store them (this is the memoization method). Or, at much worse performance, you can recalculate each Fibonacci number that you need, even if you've already calculated it before. Clearly, without memoization, you will need to do exponentially more work, and for high Fibonacci numbers, this really makes a difference, as you've observed.

Error in finding nth fibonacci number
By : Scriptkiddie
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The error you are getting is stack overflow. This is caused since the stack allocated for your thread is 1MB (by default) and your program have a recursive function call with depth of 5 million. In order to fix this problem, you can just reverse the iteration, like that:

