[GeeksForGeeks] Check Fibonacci Number

Give a number n, check if it is a fibonacci number.

 

Solution 1.  Generate a sequence of fibonacci number until we have a fibonacci number that is either greater than or equal to n.

If greater than, return false; If equal to, return true.

 

Solution 2. 

A number is Fibonacci if and only if one or both of (5*n^2 + 4) or (5*n^2 – 4) is a perfect square (Source: Wiki). 

 

posted @ 2017-08-01 00:48  Review->Improve  阅读(136)  评论(0编辑  收藏  举报