快速求斐波那契数列<黄金分割率>

有一个固定的数学公式= =,不知道的话显然没法应用

a(n)为斐波那契数第n项

O(1)复杂度

Python

def fib(self, N):
  golden_ratio = (1 + 5 ** 0.5) / 2
  return int((golden_ratio ** N + 1) / 5 ** 0.5)

猜你喜欢

转载自www.cnblogs.com/shitianfang/p/12347963.html