Fast Fibonacci recursion

前端 未结 9 1692

I\'m trying to recall an algorithm on Fibonacci recursion. The following:

public int fibonacci(int n)  {
  if(n == 0)
    return 0;
  else if(n == 1)
    ret         


        
9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 23:58

    This kind of problems are linear recurrence types and they are solved fastest via fast matrix exponentiation. Here's the blogpost that describes this kind of approach concisely.

提交回复
热议问题