We are given a variable n, we need to find whether Fibonacci number will be multiple of 10 or not.
Input : 15 Output : Yes Input : 17 Output : No
A Simple Method is to find nth Fibonacci number and check if it is divisible by 10 or not.
Efficient Method :
The above solution may not work if n is very large, then it is not possible to find fibonacci number. Moreover, we can check without finding fibonacci number by looking on the pattern. Let’s see how !
If number is divisible by 10, then it must have to be divisible by 5 and 2 both.
Multiples of 2 in Fibonacci Series :
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 ….
The number shown in bold are divisible by 2. On careful observation, we finds that every 3rd number is divisible by 2.
Multiples of 5 in Fibonacci Series :
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 ……
The number shown in bold are divisible by 5. On careful observation, we find that every 5-th number is divisible by 5.
Now LCM of 3 and 5 is 15. So, every 15-th Fibonacci number will be divisible by 10. So, we don’t need to find Fibonacci number, just we have to check if n is divisible by 15 or not. Below is the implementation.
# A simple Python 3 program to check if
# n-th Fibonacci number is multiple
# of 10.
# Returns true if n-th Fibonacci number
# is multiple of 10.
return (n % 15 == 0)
# Driver Code
n = 30
# This code is contributed
# by Akanksha Rai
This code runs in O(1) time.
This article is contributed by Aditya Kumar. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Write an Efficient Method to Check if a Number is Multiple of 3
- Space efficient iterative method to Fibonacci number
- n'th multiple of a number in Fibonacci Series
- C/C++ Program for nth multiple of a number in Fibonacci Series
- Check if a M-th fibonacci number divides N-th fibonacci number
- Check if a given number is Pronic | Efficient Approach
- Check if a number is multiple of 5 without using / and % operators
- Check whether a very large number of the given form is a multiple of 3.
- How to check if a given number is Fibonacci number?
- Check if the n-th term is odd or even in a Fibonacci like sequence
- Write an Efficient C Program to Reverse Bits of a Number
- Efficient program to print the number of factors of n numbers
- Efficient program to print all prime factors of a given number
- Check whether frequency of characters in a string makes Fibonacci Sequence
- Number of ways to represent a number as sum of k fibonacci numbers