VOOZH about

URL: https://www.geeksforgeeks.org/dsa/lcm-and-hcf-of-fractions/

⇱ LCM and HCF of fractions - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LCM and HCF of fractions

Last Updated : 11 Jul, 2022

Given n fractions as two arrays Num and Den. The task is to find out the L.C.M of the fractions.

Examples: 

Input: num[] = {1, 7, 4}, den[] = {2, 3, 6} 
Output: LCM is = 28/1 
The given fractions are 1/2, 7/3 and 4/6. 
The LCM is 28/1

Input: num[] = {24, 48, 72, 96}, den[] = {2, 6, 8, 3} 
Output: LCM is = 288/1 
 

LCM of A/B and C/D = (LCM of A and C) / (HCF of B and D) 
 

👁 Image


Below is the implementation of above approach:


Output: 
LCM is = 28/1

 

Time Complexity: O(N * log(min(a, b)))

Auxiliary Space: O(log(min(a, b)))

Given n fractions as two arrays Num and Den. The task is to find out the L.C.M of the fractions. 

Input: num[] = {1, 7, 4}, den[] = {2, 3, 6} 
Output: HCF is 1/6 
The given fractions are 1/2, 7/3 and 4/6. 
The HCF is 1/6

Input: num[] = {24, 48, 72, 96}, den[] = {2, 6, 8, 3} 
Output: HCF is 1/1 
 

HCF of A/B and C/D = (HCF of A and C) / (LCM of B and D) 
 

👁 Image


Below is the implementation of above approach: 


Output: 
HCF is = 1/1

 
Comment
Article Tags:
Article Tags: