Test if a number is fibonacci

后端 未结 20 881
深忆病人
深忆病人 2020-11-30 17:58

I know how to make the list of the Fibonacci numbers, but i don\'t know how can i test if a given number belongs to the fibonacci list - one way that comes in mind is genera

20条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 18:15

    From Wikipedia: http://en.wikipedia.org/wiki/Fibonacci_number

    A positive integer z is a Fibonacci number if and only if one of 5z^2 + 4 or 5z^2 − 4 is a perfect square.

提交回复
热议问题