Solution (source code)

= Solution

Emit separators only between terms, with a special case for the empty sum:

``
procedure OutRat(m,n)
    Out.Int(m)
    Out.String("/")
    Out.Int(n)

procedure OutEgypt(e)
    if e.i = 0 then
        Out.String("0")
    else
        for j := 0 to e.i-1 do
            if j > 0 then Out.String("+")
            Out.String("1/")
            Out.Int(e.x[j])
``

Ordinary unpadded decimal output and the <greedy Egyptian fraction expansion> give \b[`5/7 = 1/2+1/5+1/70`] for that input. The final newline is supplied by the caller. Stored duplicate denominators, if present in another valid representation, are printed as separate <unit fraction> occurrences.