ForHosting KIT · Math

Ulam sequence calculator

The first ten Ulam numbers are 1, 2, 3, 4, 6, 8, 11, 13, 16 and 18, so the tenth is 18. Enter how many terms you need to get the ordered list and its last value. 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
N
10
You get
Last
18

The Ulam sequence is the integer sequence that begins with one and two, then repeatedly appends the smallest integer that can be written as a sum of two distinct earlier terms in exactly one way. That unique-sum rule is easy to state and surprisingly rich: early terms look almost arithmetic, then gaps appear, then irregular clusters that still have no simple closed form. Students meet the sequence in recreational number theory, programming contests ask for the first n terms or the n-th Ulam number, and research notes still study its density. This capability accepts a positive integer n and returns the ordered prefix of length n, the last term, and a short formula string that restates the definition.

How the Ulam sequence is defined and why unique sums matter

Stanisław Ulam defined the sequence so that the first two terms are one and two, and every later term is the least integer strictly larger than the previous term that admits exactly one representation as a sum of two distinct earlier members.

Under that rule three equals one plus two (unique), four equals one plus three (unique; two plus two is disallowed because the summands must be distinct), five equals both one plus four and two plus three (two ways, so five is skipped), six equals only two plus four among pairs of earlier terms, and the sequence continues eight, eleven, thirteen, sixteen, eighteen, and so on.

The uniqueness filter is what separates Ulam numbers from the set of all sums of earlier pairs: many candidates have two or more representations and are rejected even though they are larger than the current maximum. There is no known simple formula for the n-th term, so trustworthy computation walks candidates upward, counts unordered pairs drawn from the terms already accepted, and accepts the first candidate with a pair count of exactly one.

That procedure is fully deterministic: the same n always yields the same ordered list, with no random seeds, clocks, floating-point drift, or network calls. When you only need the n-th value, read the last field of the response; when you need the entire history for a lecture slide or a contest checker, use the sequence array as-is.

Where the Ulam sequence is useful

Number theory courses and recreational math clubs use an Ulam sequence calculator so learners can generate a trustworthy prefix without hand-counting pair sums for every candidate. Research notebooks that explore gaps, density conjectures, or comparisons with related additive bases benefit from a shared reference implementation rather than re-coding the unique-sum loop in every language. Product demos and interview questions about additive bases can show a short table next to Fibonacci or Sylvester growth without pretending there is a closed form.

Keep n within the published limit, pin the sequence array in tests, and you get reproducible Ulam prefixes for homework, CMS plugins, and edge workers without standing up symbolic math infrastructure of your own. If you later need only the n-th term under a different indexing convention, modular Ulam-like sequences, or uniqueness counts for arbitrary bases, treat those as separate search intents rather than overloading this landing.

Classroom and homework checks

Let students request the first n Ulam numbers and verify that each term after two has a unique sum of two earlier terms, catching common mistakes like including five or seven.

Research notebooks and gap plots

Pull exact leading terms into scripts that study gaps, density, or additive bases without reimplementing the unique-sum search each time.

What is the Ulam sequence?

It starts with 1 and 2. Each later term is the smallest integer greater than the previous term that can be written as a sum of two distinct earlier terms in exactly one way.

What does this calculator return for a given n?

The first n Ulam numbers as sequence, the n-th term as last, the echoed n, and a short formula string.

What happens if n is below one?

Sequence length must be at least 1; zero and negative n are not rewritten into defaults.

Why is 5 not an Ulam number?

Five equals both 1+4 and 2+3, so it has two representations as a sum of earlier terms and is skipped by the unique-sum rule.

What are the first ten Ulam numbers?

They are 1, 2, 3, 4, 6, 8, 11, 13, 16 and 18. Numbers such as 5 or 7 are skipped because they can be built from two earlier terms in more than one way.

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/ulam-sequence

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/ulam-sequence \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":10}'
{
  "n": 10
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.ulam_sequence",
  "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.

min_n1
max_n500
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.

Requests with n below one fail with invalid_input instead of inventing an empty or shifted sequence. The free browser path and the paid API share one pure deterministic module, so classroom demos and automated pipelines never disagree on whether five or seven belongs in the list.

Input contract, response shape, and error behaviour

Failed validation is not billed. POST a JSON body with a single required integer field n, the number of leading Ulam terms you want. Aliases count, length, and terms are accepted for the same meaning. The value must be an integer from one through five hundred inclusive; numeric strings that are exact integers are allowed, but decimals, non-numeric tokens, missing fields, and empty strings fail with invalid_input naming the problem. If n exceeds five hundred the request is rejected so worst-case latency stays suitable for a free in-browser tool and a lightweight Worker path. On success the body includes the normalized n, sequence as an ascending array of ordinary JSON numbers (safe for every supported n because Ulam terms grow roughly linearly with index in this range), last equal to sequence[n-1], and formula restating the classic definition for display next to the answer. Example checks: n equals one yields sequence one and last one; n equals two yields one then two; n equals ten yields one, two, three, four, six, eight, eleven, thirteen, sixteen, eighteen with last eighteen; n equals zero or negative n yields invalid_input.

Where an Ulam sequence API earns its keep

Programming contest authors and LMS graders need a deterministic oracle that marks wrong any list that includes five or seven among the early terms, and that rejects n less than one instead of returning an empty success payload a buggy grader might treat as correct.

Contest fixtures and auto-grading

Generate deterministic Ulam prefixes for programming problems and mark submissions against a trusted oracle that rejects n below one.

What does the Ulam sequence calculator 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 →