nth fibonacci number in sublinear time

2019-01-01 06:26发布

Is there any algorithm to compute the nth fibonacci number in sub linear time?

13条回答
与风俱净
2楼-- · 2019-01-01 07:22

One of the exercises in SICP is about this, which has the answer described here.

In the imperative style, the program would look something like

Function Fib(count)
    a ← 1
    b ← 0
    p ← 0
    q ← 1

    While count > 0 Do
        If Even(count) Then
             pp² + q²
             q ← 2pq + q²
             countcount ÷ 2
        Else
             abq + aq + ap
             bbp + aq
             countcount - 1
        End If
    End While

    Return b
End Function
查看更多
登录 后发表回答