Split the fraction into sum of multiple fractions having numerator as 1 | 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 ; Given Input ; Function Call ; Print Answer
def FractionSplit ( n , d ) : NEW_LINE INDENT UnitFactions = [ ] NEW_LINE while ( n > 0 ) : NEW_LINE INDENT x = ( d + n - 1 ) // n NEW_LINE s = "1 / " + str ( x ) NEW_LINE UnitFactions . append ( s ) ; NEW_LINE n = n * x - d ; NEW_LINE d = d * x NEW_LINE DEDENT return UnitFactions ; NEW_LINE DEDENT n = 13 ; NEW_LINE d = 18 ; NEW_LINE res = FractionSplit ( n , d ) ; NEW_LINE for s in res : NEW_LINE INDENT print ( s + " , ▁ " , end = " ▁ " ) ; NEW_LINE DEDENT