Triangular number calculator
The 5th triangular number is 15 and the 10th is 55. Enter a position to get n(n+1)/2, enter any whole number to learn whether it is triangular and where it sits in the sequence, or do both at once. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 5
- Triangular
- 15
- Product
- 30
A triangular number counts objects that form an equilateral triangle: one on the first row, two on the second, three on the third, and so on. The closed formula is simple and exact—T sub n equals n times n plus one, all over two—so the fifth triangular number is fifteen, the tenth is fifty-five, and the hundredth is five thousand fifty. This capability both evaluates that formula for a non-negative index n and tests whether an arbitrary non-negative integer is triangular by checking that one plus eight times the value is a perfect square.
What triangular numbers are and how the formula works
Imagine stacking coins in rows: one coin, then a row of two, then three, and so on up to n rows. The total count is the n-th triangular number. Adding one through n is the same as the closed product formula n times n plus one divided by two, because n and n plus one are consecutive integers and therefore one of them is even, so the division by two is exact in integer arithmetic.
The sequence begins zero (for n equals zero, an empty triangle), then one, three, six, ten, fifteen, twenty-one, twenty-eight, thirty-six, forty-five, and fifty-five for n equals ten. Triangular numbers appear in combinatorics as the number of edges in a complete graph on n plus one vertices, in the handshake problem, and as figurate numbers related to square numbers through identities such as eight T sub n plus one equals the square of two n plus one.
Because every step is integer multiplication and an exact half, there is no rounding, no sampling, and no dependence on wall-clock time or random seeds.
What you can do with it
Programming contest and interview prep validators
Assert candidate solutions for classic triangular-number problems without reimplementing the closed formula and perfect-square inverse in every language harness.
FAQ
What is a triangular number?
A non-negative integer of the form T_n = n(n+1)/2 for some integer n ≥ 0. Examples: 1, 3, 6, 10, 15, 21.
How do you test whether a value is triangular?
Compute 1 + 8·value. If that discriminant is a perfect square r² with r odd, then n = (r−1)/2 and the value equals T_n.
Is the triangular number calculator free?
The browser tool is free and runs locally.
Is 0 a triangular number?
Yes. It is the triangular number at position 0, an empty triangle with no rows, so the sequence starts 0, 1, 3, 6, 10. Checking the value 0 therefore reports it as triangular.
How many handshakes happen when everyone in a group shakes hands once?
A triangular number of them. With 6 people the count is the 5th triangular number, 15, because each pair shakes hands once. In general, a group of n plus one people makes the n-th triangular number of handshakes.
Related tools
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/triangular-number \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5}'const res = await fetch("https://api.kit.forhosting.com/math/triangular-number", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 5
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/triangular-number",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 5
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/triangular-number", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":5}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":5}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/triangular-number", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 5
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.triangular_number",
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_n | 100000000 |
max_value | 5000000050000000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Students, teachers, contest authors, and data-pipeline builders get a deterministic JSON answer with no computer-algebra system, no floating-point guesswork, and the same pure function in the free browser tool and the prepaid API path.
What triangular numbers are and how the formula works
When you only need T sub n, send the index; when you need membership, send the candidate value; when you need both in one call, send both fields and read triangular and is_triangular together.
How to call the API and what comes back
Field n is a non-negative whole number at most one hundred million—the index of the triangular number you want. Field value is a non-negative whole number at most five quadrillion fifty billion—the candidate you want to test for triangular membership. On a compute path the response includes n, triangular equal to T sub n, product equal to n times n plus one, and the formula string n times n plus one over two. Use it from homework pipelines, programming-contest validators, interview-prep sandboxes, spreadsheet enrichment jobs, or any workflow that needs a reproducible triangular-number check without installing specialized number packages on every machine. Send a JSON body with at least one of two fields. Aliases index and order are accepted for the same meaning. Aliases number, x, and candidate map to value. On a check path the response includes value, is_triangular as a boolean, root_n as the recovered index or null, discriminant equal to one plus eight times value, and when the candidate is triangular also n, triangular, and product so you can recompute by hand. Failed validation—missing both fields, a non-integer, a fraction, a value above the published limit, or any negative number—returns invalid_input and is never charged. Pricing is a flat $0.002 per successful request with unit item and zero marginal unit price.
Practical tips, limits, and related searches
If you need multiprecision figurate numbers with hundreds of digits, use a dedicated big-integer stack—this lightweight parse capability is built for interactive checks and teaching-sized inputs. Sibling number-theory landings in this kit target other intents such as Armstrong checks or aliquot sums; this page is specifically for people searching for a triangular number calculator or asking whether a given integer is triangular. Prefer the dual-field design over inventing a mode enum: one contract covers compute-only, check-only, and joint requests without breaking older clients. Keep n and value inside the published safe-integer limits so every intermediate product and the discriminant one plus eight v stay exact on the Worker and in the browser. When teaching, prefer paired examples: n equals five yields fifteen; value equals fifteen yields is_triangular true with root_n five; value equals fourteen yields false; and a negative n demonstrates the hard rejection path. Because the inverse rests on a perfect-square test of the discriminant, students can recompute the square root by hand for small cases and match the API line by line. Do not treat the boolean alone as a black box—pair is_triangular with root_n and discriminant when grading submissions so wrong inverse formulas are easy to diagnose. Failed tasks that return invalid_input do not consume prepaid balance, which keeps exploratory scripts cheap when users type bad values while learning the contract.
Integration use cases
Homework: compute T_n and verify triangular membership
Give students an index or a candidate integer and check their hand-computed triangular value or yes/no label against a deterministic API or free browser result.
Teaching demos of figurate numbers and closed sums
Project n, product, triangular, discriminant, and root_n in class so learners see the formula, the inverse square test, and both outcomes in one response.
Technical questions
Is zero a triangular number?
Yes. For n = 0, T_0 = 0. This tool treats zero as a valid non-negative triangular number.
What inputs are rejected?
Missing both n and value, non-integers, values above the published maxima, and any negative number return invalid_input. Those failures are not charged.