+ 6

How to calculate fabonacci series that the number is over 4000000000?

12th May 2018, 1:34 PM
Wuttyee Wynn
Wuttyee Wynn - avatar
6 Answers
+ 23
you have to use big integers.. or implement one of your own. number of digits of fib(n) for large inputs could be scary!
12th May 2018, 2:01 PM
Amir
Amir - avatar
+ 4
An attempt, if you are interested. https://code.sololearn.com/cqtn357OfStn/#cpp
12th May 2018, 2:01 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
you could try this (im not really good at c++, but it should be possible) a=0 b=1 c=a+b //1 and after that var a= c //1 var b= a+b //2 var c= a+b //3 and somehow loop that, but i dont know about loops in c++
12th May 2018, 1:40 PM
Roel
Roel - avatar
+ 2
Thank you Roel and Donna
12th May 2018, 1:51 PM
Wuttyee Wynn
Wuttyee Wynn - avatar
+ 1
Use binet's formula : o(1). Or fast matrix exponent o(log(n) https://code.sololearn.com/cEal5s0hfuC8/?ref=app
12th May 2018, 6:24 PM
VcC
VcC - avatar