Given a number ‘n’, how to check if n is a Fibonacci number. First few Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 141, ..
Input : 8 Output : Yes Input : 34 Output : Yes Input : 41 Output : No
Following is an interesting property about Fibonacci numbers that can also be used to check if a given number is Fibonacci or not.
A number is Fibonacci if and only if one or both of (5*n2 + 4) or (5*n2 – 4) is a perfect square (Source: Wiki).
1 is a Fibonacci Number 2 is a Fibonacci Number 3 is a Fibonacci Number 4 is a not Fibonacci Number 5 is a Fibonacci Number 6 is a not Fibonacci Number 7 is a not Fibonacci Number 8 is a Fibonacci Number 9 is a not Fibonacci Number 10 is a not Fibonacci Number
Please refer complete article on How to check if a given number is Fibonacci number? for more details!
- Java Program for nth multiple of a number in Fibonacci Series
- Java Program to check Armstrong Number
- Java program to check if a number is prime or not
- Java Program to Check if all digits of a number divide it
- Java Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Java Program to Find the Number Occurring Odd Number of Times
- Java Program for n-th Fibonacci numbers
- Java Program for Zeckendorf\'s Theorem (Non-Neighbouring Fibonacci Representation)
- Java Program for factorial of a number
- Java Program for Sum the digits of a given number
- Java Program for nth Catalan Number
- Java Program for Triangular Matchstick Number
- Java Program to Find sum of even factors of a number
- Java Program for Print Number series without using any loop
- Java Program for Number of stopping station problem