Iterative Approach using a List
Another approach involves generating the Fibonacci series and checking for multiples of k. This function iteratively generates the Fibonacci series and checks for multiples of k.
Example: Finding the Position of nth Multiple of a Number in the Fibonacci Series using Iterative Approach in JavaScript.
Javascript
// JavaScript function to find the position // of nth multiple of a number k in the // Fibonacci Series using an iterative approach function nthFibMultiple(n, k) { let fibonacci = [0, 1]; let counter = 0; for (let i = 2; ; i++) { let current = fibonacci[i - 1] + fibonacci[i - 2]; if (current % k === 0) { counter++; if (counter === n) { return i; } } fibonacci.push(current); } } console.log(nthFibMultiple(3, 2)); |
9
Time Complexity: O(N)
Space Complexity: O(N)
nth Multiple of a Number in Fibonacci Series in JavaScript
The Fibonacci series is a sequence of numbers where each number is the sum of the two previous ones, usually starting with 0 and 1. Given two integers n and k, the task is to find the position of the nth multiple of k in the Fibonacci series. For instance, if k = 2 and n = 3, the output would be 9 since the third multiple of 2 in the Fibonacci series is 34, which appears at position 9. There are multiple ways to find the nth multiple of a number in the Fibonacci series in Javascript which is as follows:
Table of Content
- Mathematical approach
- Iterative Approach using a List
- Recursive Fibonacci Series with Memoization