Skip to content
the poor coder

Hackerrank - Is Fibo Solution

Poor Man
Published
Updated
Reading time
1 min read

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

Text
3
5
7
8

Sample Output

Text
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#

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())))

Keep going

2020

Hackerrank - Bus Station Solution

There are groups of friends, and each group is numbered from 1 to . The th group contains people. They live near a bus stop, and only a single bus operates on this route. An empty bus arrives at the bus stop and all the…

2020

Hackerrank - K Candy Store Solution

Jim enters a candy shop which has N different types of candies, each candy is of the same price. Jim has enough money to buy K candies. In how many different ways can he purchase K candies if there are infinite candies…

2020

Hackerrank - Diwali Lights Solution

On the eve of Diwali, Hari is decorating his house with a serial light bulb set. The serial light bulb set has N bulbs placed sequentially on a string which is programmed to change patterns every second. If at least one…

ESC