问题
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