Split the fraction into sum of multiple fractions having numerator as 1 | C # program for the above approach ; Function to split the fraction into distinct unit fraction ; To store answer ; While numerator is positive ; Finding x = ceil ( d / n ) ; Add 1 / x to list of ans ; Update fraction ; Driver code ; Given Input ; Function Call ; Print Answer
using System ; using System . Collections . Generic ; class GFG { static List < string > FractionSplit ( long n , long d ) { List < string > UnitFactions = new List < string > ( ) ; while ( n > 0 ) { long x = ( d + n - 1 ) / n ; string s = "1 / " + x . ToString ( ) ; UnitFactions . Add ( s ) ; n = n * x - d ; d = d * x ; } return UnitFactions ; } public static void Main ( string [ ] args ) { long n = 13 , d = 18 ; List < string > res = FractionSplit ( n , d ) ; foreach ( string s in res ) Console . Write ( s + " , ▁ " ) ; } }