Finding the closest fibonacci numbers

前端 未结 11 2157

I am trying to solve a bigger problem, and I think that an important part of the program is spent on inefficient computations.

I need to compute for a given number N, th

11条回答
  •  梦毁少年i
    2021-02-02 14:08

    Using the last form here for the inverse you can find the two indexes for the Fib numbers around the current number. http://en.wikipedia.org/wiki/Fibonacci_number#Computation_by_rounding

    log(N * sqrt(5)) / log((1+sqrt(5))/2) should give you a number which is between the two integer indexes for P and Q. You can then used the closed-form (as shown in the other answers) to give the actual numbers P and Q.

    Note that you may be off by one depending on your initial Fib conditions.

提交回复
热议问题