VOOZH about

URL: https://www.geeksforgeeks.org/python/python-program-for-nth-multiple-of-a-number-in-fibonacci-series/

⇱ Nth multiple of a number in Fibonacci Series in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Nth multiple of a number in Fibonacci Series in Python

Last Updated : 10 Nov, 2025

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.

Iterative Approach

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.


Output
987

Explanation:

  • a, b = b, a + b: generates Fibonacci numbers iteratively.
  • if b % m == 0: checks if current Fibonacci number is divisible by m.
  • count: keeps track of how many multiples have been found.
  • When count == n, the nth multiple is printed.

Dynamic Programming

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.


Output
987

Explanation:

  • fib.append(fib[-1] + fib[-2]): appends the next Fibonacci number.
  • fib[-1] % m == 0: checks for divisibility.
  • When count equals n, the function returns the required Fibonacci number.

Recursive Approach with Memoization

This method calculates Fibonacci numbers recursively while storing results in a dictionary to avoid redundant calculations.


Output
987

Explanation:

  • fib(n, memo): recursively calculates the nᵗʰ Fibonacci number using memoization for faster lookup.
  • while loop: iterates through Fibonacci numbers starting from index 2.
  • value % m == 0 (Divisibility check): increments a counter each time a Fibonacci number is divisible by m.

Related Articles:

Comment
Article Tags:
Article Tags: