Given here are two positive numbers a and b. The task is to print the least common multiple of a’th and b’th Fibonacci Numbers.
The first few Fibonacci Numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……
Note that 0 is considered as 0’th Fibonacci Number.
Input : a = 3, b = 12 Output : 144 Input : a = 8, b = 37 Output : 507314157
Approach: The simple solution of the problem is,
- Find the a’th fibonacci number.
- Find the b’th fibonacci number.
- Find their GCD, and with the help of the GCD find their LCM. The relation is LCM(a, b) = (a x b) / GCD(a, b) (Please refer here).
Below is the implementation of the above approach:
// Java ram to find LCM of Fib(a)
// and Fib(b)
static int MAX = 1000;
// Create an array for memoization
static int f = new int[MAX];
// Function to return the n’th Fibonacci
// number using table f.
static int fib(int n)
// Base cases
if (n == 0)
if (n == 1 || n == 2)
return (f[n] = 1);
// If fib(n) is already computed
if (f[n] != 0)
int k = 0;
if ((n & 1) != 0)
k = (n + 1) / 2;
k = n / 2;
// Applying recursive formula
// Note value n&1 is 1
// if n is odd, else 0.
if((n & 1 ) != 0)
f[n] = (fib(k) * fib(k) +
fib(k – 1) * fib(k – 1));
f[n] = (2 * fib(k – 1) +
fib(k)) * fib(k);
// Function to return gcd of a and b
static int gcd(int a, int b)
if (a == 0)
return gcd(b % a, a);
// Function to return the LCM of
// Fib(a) and Fib(a)
static int findLCMFibonacci(int a, int b)
return (fib(a) * fib(b)) / fib(gcd(a, b));
// Driver code
public static void main(String args)
int a = 3, b = 12;
// This code is contributed by
- Program to find last digit of n'th Fibonnaci Number
- Program to find LCM of two numbers
- Program to find GCD or HCF of two numbers
- Program to find LCM of 2 numbers without using GCD
- Program to find sum of prime numbers between 1 to n
- Program to find first N Iccanobif Numbers
- Program to find sum of first n natural numbers
- Program to find the percentage of difference between two numbers
- Program to find GCD of floating point numbers
- Program to find the common ratio of three numbers
- Program to find GCD or HCF of two numbers using Middle School Procedure
- Program to find HCF (Highest Common Factor) of 2 Numbers
- Program to find count of numbers having odd number of divisors in given range
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
- Program for Fibonacci numbers
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.