Hackerrank - Is Fibo Solution
1 min read

Hackerrank - Is Fibo Solution

Hackerrank - Is Fibo Solution

You are given an integer, . Write a program to determine if  is an element of the Fibonacci sequence.

The first few elements of the Fibonacci sequence are . A Fibonacci sequence is one where every element is a sum of the previous two elements in the sequence. The first two elements are  and .

Formally:

Input Format
The first line contains , number of test cases.
lines follow. Each line contains an integer .

Output Format
Display IsFibo if  is a Fibonacci number and IsNotFibo if it is not. The output for each test case should be displayed in a new line.

Constraints

Sample Input

3
5
7
8

Sample Output

IsFibo
IsNotFibo
IsFibo

Explanation
is a Fibonacci number given by
is not a Fibonacci number
is a Fibonacci number given by

Time Limit
Time limit for this challenge is given here.

Solution in Python

def solve(n):
    a = 0
    b = 1
    while a<n:
        a,b = b,a+b
    return "IsFibo" if a==n else "IsNotFibo"

for _ in range(int(input())):
    print(solve(int(input())))

Enjoying these posts? Subscribe for more


Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.

×