Given a number N, the task is to find the next Non-Fibonacci number.
Input: N = 4
6 is the next non-fibonacci number after 4
Input: N = 6
Approach: As the fibonacci series is given as
0, 1, 1, 2, 3, 5, 8, 13, 21, 34….
It can be observed that there does not exists any 2 consecutive fibonacci numbers. Therefore, inorder to find the next Non-Fibonacci number, the following cases arise:
- If N <= 3, then the next Non-Fibonacci number will be 4
- If N > 3, then we will check if (N + 1) is fibonacci number or not.
- If (N + 1) is a fibonacci number then (N + 2) will be the next Non-Fibonacci number.
- Else (N + 1) will be the answer
Below is the implementation of the above approach:
4 6 9
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find minimum number to be divided to make a number a perfect square
- Find the largest number smaller than integer N with maximum number of set bits
- Find smallest number formed by inverting digits of given number N
- Find the minimum number to be added to N to make it a prime number
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Find smallest possible Number from a given large Number with same count of digits
- Given number of matches played, find number of teams in tournament
- Find count of digits in a number that divide the number
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Find the smallest number whose digits multiply to a given number n
- Find the number of ways to divide number into four parts such that a = c and b = d
- Find the total number of composite factor for a given number
- Find the number of jumps to reach X in the number line from zero
- Find the largest good number in the divisors of given number N
- Find maximum number that can be formed using digits of a given number
- Find the maximum number of composite summands of a number
- Find M-th number whose repeated sum of digits of a number is N
- Find if a number is divisible by every number in a list
- Find Nth number in a sequence which is not a multiple of a given number
- Find the sequence number of a triangular number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.