Given two integers n and k. Find position the n\’th multiple of K in the Fibonacci series.
Input : k = 2, n = 3 Output : 9 3\'rd multiple of 2 in Fibonacci Series is 34 which appears at position 9. Input : k = 4, n = 5 Output : 30 5\'th multiple of 5 in Fibonacci Series is 832040 which appears at position 30.
An Efficient Solution is based on below interesting property.
Fibonacci series is always periodic under modular representation. Below are examples.
F (mod 2) = 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0, 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0 Here 0 is repeating at every 3rd index and the cycle repeats at every 3rd index. F (mod 3) = 1,1,2,0,2,2,1,0,1,1,2,0,2,2,1,0 ,1,1,2,0,2,2,1,0,1,1,2,0,2,2 Here 0 is repeating at every 4th index and the cycle repeats at every 8th index. F (mod 4) = 1,1,2,3,1,0,1,1,2,3,1,0,1,1,2,3, 1,0,1,1,2,3,1,0,1,1,2,3,1,0 Here 0 is repeating at every 6th index and the cycle repeats at every 6th index. F (mod 5) = 1,1,2,3,0,3,3,1,4,0,4,4,3,2,0, 2,2,4,1,0,1,1,2,3,0,3,3,1,4,0 Here 0 is repeating at every 5th index and the cycle repeats at every 20th index. F (mod 6) = 1,1,2,3,5,2,1,3,4,1,5,0,5,5,4, 3,1,4,5,3,2,5,1,0,1,1,2,3,5,2 Here 0 is repeating at every 12th index and the cycle repeats at every 24th index. F (mod 7) = 1,1,2,3,5,1,6,0,6,6,5,4,2,6,1, 0,1,1,2,3,5,1,6,0,6,6,5,4,2,6 Here 0 is repeating at every 8th index and the cycle repeats at every 16th index. F (mod 8) = 1,1,2,3,5,0,5,5,2,7,1,0,1,1,2, 3,5,0,5,5,2,7,1,0,1,1,2,3,5,0 Here 0 is repeating at every 6th index and the cycle repeats at every 12th index. F (mod 9) = 1,1,2,3,5,8,4,3,7,1,8,0,8,8,7, 6,4,1,5,6,2,8,1,0,1,1,2,3,5,8 Here 0 is repeating at every 12th index and the cycle repeats at every 24th index. F (mod 10) = 1,1,2,3,5,8,3,1,4,5,9,4,3,7,0, 7,7,4,1,5,6,1,7,8,5,3,8,1,9,0. Here 0 is repeating at every 15th index and the cycle repeats at every 60th index.
Position of n'th multiple of k inFibonacci Seires is 30
Please refer complete article on n’th multiple of a number in Fibonacci Series for more details!
- Python | Find fibonacci series upto n using lambda
- Python Program for How to check if a given number is Fibonacci number?
- Add, subtract, multiple and divide two Pandas Series
- Python Program for n-th Fibonacci number
- Python Program for Fibonacci numbers
- Python Program for Zeckendorf\'s Theorem (Non-Neighbouring Fibonacci Representation)
- Python Program for Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Python Program for Print Number series without using any loop
- Python | Plotting Fibonacci spiral fractal using Turtle
- Python Program for Find sum of Series with n-th term as n^2 - (n-1)^2
- Rename multiple files using Python
- Python | Write multiple files data to master file
- Remove multiple elements from a list in Python
- Python | Interleave multiple lists of same length
- Python | Add similar value multiple times in list
- Python | Initializing multiple lists
- Python | Assign multiple variables with list values
- Python | Replace multiple occurrence of character by single
- Python | Append multiple lists at once
- Python | Intersection of multiple lists