VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-lcm-rational-numbers/

⇱ Find LCM of rational numbers - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find LCM of rational numbers

Last Updated : 28 Jul, 2022

Given an array of rational numbers, the task is to find the LCM of these numbers.

Examples: 

Input : vect[] = {2/7, 3/14, 5/3}
Output : 30/1

Input : vect[] = {3/14, 5/3}
Output : 15/1

Input : vect[] = {3/4, 3/2}
Output : 3/2

First find the lcm of all numerator of rational number then find the gcd of all the denominator of rational number then divide lcm of all numerator/ gcd of all the denominator this the lcm of rational number's.
Formula:- 

 LCM of all the numerator of Rational number's
lcm = -----------------------------------------------
 GCD of all the denominator of Rational number's

Implementation:


Output
30/1

Time Complexity: O(n log(min(v))), where v is the minimum element of vector 
Auxiliary Space: O(1)

Please suggest if someone has a better solution which is more efficient in terms of space and time.

Comment