Given two numbers M and N, the task is to check if the M-th and N-th Fibonacci numbers perfectly divide each other or not.
Input: M = 3, N = 6
F(3) = 2, F(6) = 8 and F(6) % F(3) = 0
Input: M = 2, N = 9
A naive approach will be to find the N-th and M-th Fibonacci numbers and check if they are perfectly divisible or not.
An efficient approach is to use the Fibonacci property to determine the result. If m perfectly divides n, then Fm also perfectly divides Fn, else it does not.
Exception: When N is 2, it is always possible as Fibo2 is 1, which divides every other Fibonacci number.
Below is the implementation of the above approach:
Time Complexity: O(1).
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.
- Program for Fibonacci numbers
- Check if the n-th term is odd or even in a Fibonacci like sequence
- Find the number of operations required to make all array elements Equal
- Modulo power for large numbers represented as strings
- Number of ways to change the XOR of two numbers by swapping the bits
- Number of quadrilaterals possible from the given points
- How to read Competitive Programming Questions?
- Python in Competitive Programming
- Sum of elements of all partitions of number such that no element is less than K
- Maximize the total profit of all the persons