Problem source: https://www.hackerrank.com/challenges/is-fibo
You are given an integer, N. Write a program to determine if N is an element of the Fibonacci sequence.
The first few elements of the Fibonacci sequence are 0,1,1,2,3,5,8,13,⋯. A Fibonacci sequence is one where every element is a sum of the previous two elements in the sequence. The first two elements are 0 and 1.
The first line contains T, number of test cases.
T lines follow. Each line contains an integer N.
IsFibo if N is a Fibonacci number and
IsNotFibo if it is not. The output for each test case should be displayed in a new line.
3 5 7 8
IsFibo IsNotFibo IsFibo Explanation: A number is Fibonacci number is (5n^2 + 4) or (5n^2 - 4) is perfect square.
static void Main(string args)
int T = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < T; ++i)
var N = Convert.ToInt64(Console.ReadLine());
bool isFibo = CheckisFibo(N);
Console.WriteLine(isFibo? "IsFibo" : "IsNotFibo");
private static bool CheckisFibo(long N)
Int64 temp = 0;
double sqrValue = (5 * Math.Pow(N, 2));
return Int64.TryParse(Math.Sqrt(sqrValue + 4).ToString(), out temp) || Int64.TryParse(Math.Sqrt(sqrValue – 4).ToString(), out temp);