How this calculation works
The first unit fraction is the largest one that fits inside the remainder. Other sums may represent the same fraction.
Repeatedly subtract 1/ceil(b/a) from the remaining fraction a/bA worked example
4/13 becomes 1/4, then 1/18, then 1/468.
Good to know
Use a proper fraction. The greedy sum can have large denominators.
Reference: OpenStax Prealgebra (opens in a new tab) ↗
Take the largest unit fraction that fits
A unit fraction has numerator one. Starting from 4/13, choose the largest unit fraction that does not exceed it. Since 13/4 = 3.25, round that denominator upward to 4 and take 1/4. The remainder is 4/13 − 1/4 = 3/52.
Repeat the rule on 3/52. The next denominator is the ceiling of 52/3, or 18, giving a remainder of 3/52 − 1/18 = 1/468. The final remainder is already a unit fraction, so the decomposition is 1/4 + 1/18 + 1/468. On a shared denominator of 468 the numerators are 117 + 26 + 1 = 144, matching 4/13 = 144/468.
Understand what the greedy rule chooses
The method makes a local choice at every step, using the largest eligible unit fraction. The next remainder is smaller, and the process terminates for a positive rational proper fraction. The denominators can become large, as 468 in this short example illustrates. Exact integer arithmetic prevents those denominators from introducing decimal-rounding errors.
A fraction can have several valid unit-fraction sums. The greedy decomposition is not guaranteed to use the smallest possible number of terms. For example, 5/21 has the two-term representation 1/6 + 1/14, while the greedy rule begins with 1/5. Use the Cross multiplication check calculator to verify a proposed sum after combining its terms into one fraction.
A few questions, answered
Why are improper fractions excluded?
This implementation decomposes a positive share below one. Separate the whole-number part of an improper fraction before decomposing its remaining proper fraction.
Does a unit fraction need more than one step?
No. An input such as 1/7 is already a complete one-term representation.