Check if a number is Fibonacci

A Fibonacci number is one which appears in the Fibonacci Sequence.

To check if a given number n occurs in the Fibonacci Sequence or not we only need to check if one or both of (5*n^2 + 4) or (5*n^2 – 4) is a perfect square or not (source: wiki).

Python code for the same:
(The code takes a number from standard input and prints on standard output whether the number is Fibonacci or not)

Rate this post

Leave a Reply