VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-n-fractions-that-sum-upto-a-given-fraction-n-d/

⇱ Find N fractions that sum upto a given fraction N/D - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find N fractions that sum upto a given fraction N/D

Last Updated : 23 May, 2022

Given a fraction N/D, the task is to split this fraction into N parts such that their sum is equal to the fraction N/D, i.e., 

Note: Represents the terms in terms of fractions, instead of floating point numbers.
 

Input: N = 4, D = 2 
Output: 4/5, 1/5, 1/3, 4/6 
Explanation: 

Therefore, it is a valid set of fractions such that their sum is 


Input: N = 3, D = 4 
Output: 1/2, 1/10, 3/20 
Explanation: 

Therefore, it is a valid set of fractions such that their sum is  

Approach: The key observation in the problem is that the first fraction numerator can be and then further denominators can be using the below recurrence relation.  




Below is the implementation of the above approach: 


Output: 
4/5, 1/5, 1/3, 4/6,

 

Time Complexity: O(n), where n is the given integer.

Auxiliary Space: O(n), where n is the given integer.

Comment
Article Tags:
Article Tags: