ForHosting KIT · Math

Egyptian fraction term count

With the greedy method, 3/4 becomes 1/2 + 1/4, so it needs 2 unit fractions. Enter a proper fraction and get the number of terms plus each unit denominator in order, so every step can be checked. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Numerator
3
Denominator
4
You get
Fraction
3/4
Term count
2
Unit denominators
2, 4

Egyptian fractions write a rational as a sum of distinct unit fractions—fractions whose numerators are one. The classical greedy method, often called the Fibonacci–Sylvester algorithm, always peels off the largest unit fraction that does not exceed the remaining value, then repeats on the remainder until nothing is left. This capability accepts a proper positive fraction numerator over denominator, runs that deterministic expansion, and returns the number of unit-fraction terms together with the ordered list of unit denominators so you can verify every step.

What a greedy Egyptian fraction expansion is

An Egyptian fraction representation of a positive rational is a finite sum of distinct unit fractions such as one half plus one third plus one seventh. Ancient Egyptian mathematics recorded many rationals this way, and modern number theory still studies shortest expansions, greedy expansions, and related Diophantine questions.

The greedy algorithm is uniquely defined: given a remainder r equals a over b with a greater than zero, choose the smallest integer k such that one over k is less than or equal to r, which is exactly k equals the ceiling of b divided by a. Subtract one over k from r to obtain a new proper remainder, reduce by the greatest common divisor, and repeat.

For three quarters the first unit fraction is one half, the remainder is one quarter, and the second unit fraction is one quarter, so the term count is two. For three sevenths the greedy steps yield one third, one eleventh, and one two-hundred-thirty-first, so the term count is three. Unit fractions already in lowest terms, such as one fifth, expand to a single term.

The algorithm is fully deterministic: no random choices, no floating-point tolerances, and no external tables. This page reports the length of that canonical greedy expansion—the term count—plus the unit denominators produced along the way, which is the quantity homework keys and programming contests most often need when they ask how many Egyptian-fraction summands the greedy method uses.

Homework and worksheet answer keys

Expand proper fractions with the greedy method and verify how many distinct unit fractions students should list for each problem.

Teaching the Fibonacci–Sylvester algorithm

Demonstrate ceiling steps on fractions such as 3/4 and 3/7, showing both the length and the ordered unit denominators.

How do you count Egyptian fraction terms with the greedy method?

Send positive integers numerator and denominator with numerator strictly less than denominator.

What happens if the numerator or denominator is non-positive?

Both fields must be positive integers; zero and negative values are rejected and not billed.

Does this find the shortest Egyptian expansion?

No. It returns the length of the classical greedy (Fibonacci–Sylvester) expansion only. Shortest expansions can differ and require a different search.

How many terms does 3/4 need?

Two. The largest unit fraction not above 3/4 is 1/2, which leaves 1/4, and that is already a unit fraction. So 3/4 = 1/2 + 1/4.

Can I enter a fraction greater than one?

No. Only proper fractions are accepted, meaning the numerator must be smaller than the denominator and both must be positive. Anything else is refused with a clear message.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/numth/egyptian-fraction-length

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/numth/egyptian-fraction-length \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"numerator":3,"denominator":4}'
{
  "numerator": 3,
  "denominator": 4
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.egyptian_fraction_length",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Students, tutors, and recreational number-theory scripts get the same answer in the free browser tool and on the prepaid API at $0.002 per successful call. Non-positive numerators or denominators, and improper fractions, fail with invalid_input and are never billed.

Input contract, response fields, and validation rules

Intermediate arithmetic uses big integers with gcd reduction so classroom-sized denominators stay exact. Pathological remainders that would force more than ten thousand terms or absurd intermediate digit growth are rejected rather than hanging the worker. POST a JSON body with two required positive integers: numerator and denominator of a proper fraction, so one is less than or equal to the numerator only when both stay positive and the numerator is strictly less than the denominator. Aliases a and num map to numerator; b and den map to denominator. Each field may arrive as a JSON number or as a digit-only string; values must be whole integers within the published upper bound of one million. If either field is missing, non-integer, zero, or negative, the task fails with invalid_input naming the rule that failed—explicitly including the non-positive case required by the product contract. If the numerator is greater than or equal to the denominator, the request is also rejected because the tool only expands proper fractions (improper inputs need an integer part stripped first by the caller). On success the body echoes numerator and denominator, a fraction display string, term_count as the number of greedy unit fractions, and unit_denominators as the ascending sequence of k values from each greedy step. Pricing is a flat $0.002 per successful request; validation failures do not consume balance.

Where term counts help study, contests, and automation

Classroom lessons on historical numeration systems often ask students to expand a handful of proper fractions by hand and count the summands. Programming-contest practice and Project Euler–style problems frequently require greedy Egyptian expansions; comparing your implementation against this oracle catches off-by-one ceiling errors and failed gcd reductions. If you need the shortest possible Egyptian representation rather than the greedy one, that is a different combinatorial search problem; this tool intentionally answers only the classical greedy length question. A deterministic Egyptian fraction term count API lets teachers publish answer keys and auto-graders without retyping expansions for every worksheet variant. Keep inputs proper and inside the published bounds, pin term_count and unit_denominators in tests, and you get reproducible expansion lengths for homework, LMS plugins, and edge workers without standing up a computer-algebra system.

Contest and library regression tests

Compare your Egyptian-fraction implementation against a deterministic term_count and unit_denominators oracle for fixed inputs.

What does a successful response include?

numerator, denominator, fraction as a display string, term_count, and unit_denominators—the ordered k values from each greedy step.

What does the Egyptian fraction term count tool cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →