![]() |
VOOZH | about |
The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, starting with 0 and 1:
0, 1, 1, 2, 3, 5, 8, 13, 21, ...
In this article, we will find the n-th Fibonacci number that is divisible by a given number m.
Example:
Input: n=2, m=3
Output: 21
Explanation: If n = 2 and m = 3, the Fibonacci numbers divisible by 3 (m) are 3, 21, 144, 987, ... Hence, the second multiple of 3 in the Fibonacci sequence is 21.
In this method, Fibonacci numbers are generated one by one in a loop. Each number is checked for divisibility by m, and a counter is increased until the n-th multiple is reached.
987
Explanation:
This approach stores previously computed Fibonacci numbers in a list to avoid redundant calculations. It avoids recalculating Fibonacci numbers by storing them in a list, making it efficient for larger inputs.
987
Explanation:
This method calculates Fibonacci numbers recursively while storing results in a dictionary to avoid redundant calculations.
987
Explanation: