nth term for Fibonacci series for enormous data input(Without Recursion or loop) [duplicate]

半城伤御伤魂 提交于 2019-12-13 08:08:12

问题


Possible Duplicate:
nth fibonacci number in sublinear time

I was creating a program which is related to the stair problem, i.e you have n stairs and the player can climb on the stairs using them one by one or skipping one ...

Now to solve this problem I needed nth (n+1)th term for the Fibonacci for n number of stairs, but the problem is my input range is 1 ≤ n ≤ 1000000.

And for that much greater value of n if I use the loop based method or recursion to calculate the Fibonacci the method takes very much time and space. That I do not have.

So please can you tell me some method in the Java or C to handle Fibonacci series up to that range with correct output?

Note: Please I do not need any solution which has recursion or loop.


回答1:


Look at the following page, maybe it will help: https://www.nayuki.io/page/fast-fibonacci-algorithms

For me their Java example managed to calculate 1000000th Fibonacci number. It is 208988 digits long.



来源:https://stackoverflow.com/questions/14689390/nth-term-for-fibonacci-series-for-enormous-data-inputwithout-recursion-or-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!