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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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 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
- Find the minimum number to be added to N to make it a prime number
- Given number of matches played, find number of teams in tournament
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Find the number of ways to divide number into four parts such that a = c and b = d
- Find the maximum number of composite summands of a number
- Find maximum number that can be formed using digits of a given number
- Find the number of jumps to reach X in the number line from zero
- Find the total number of composite factor for a given number
- Find count of digits in a number that divide the number
- Find the largest good number in the divisors of given number N
- Find the smallest number whose digits multiply to a given number n
- Find if a number is divisible by every number in a list
- Find M-th number whose repeated sum of digits of a number is N
- Find the sequence number of a triangular number
- Find Next number having distinct digits from the given number N
- Find n'th number in a number system with only 3 and 4
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.