Consecutive integers calculator
Find the run of consecutive integers that adds up to the total you choose: three numbers summing to 15 are 4, 5 and 6. It also handles negative totals and runs that cross zero, and says plainly when no run exists. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Target
- 15
- Quantity
- 3
- First
- 4
- Last
- 6
- Integers
- 4, 5, 6
Given a target sum and a count, this calculator finds the exact run of consecutive integers that adds up to it — or tells you plainly that no such run exists. Ask for 3 numbers that sum to 15 and you get 4, 5, 6; ask for 3 numbers that sum to 8 and you get an honest no. The answer is computed by a closed-form formula, not by guessing, so it is instant and exact for any integers, including negative targets and runs that cross zero.
What a consecutive-integer run is
A run of consecutive integers is a sequence where each number is exactly one more than the previous one, such as 4, 5, 6 or −2, −1, 0, 1, 2. The question this tool answers is a classic of elementary number theory: given a target sum T and a count n, is there a run of n consecutive integers whose total is exactly T, and if so, where does it start? The key insight is that any such run is fully described by its first term a.
The run is a, a+1, …, a+(n−1), and its sum is n·a plus the triangular number n(n−1)/2. So the problem reduces to solving a single linear equation: a = (T − n(n−1)/2) / n. If that value is a whole number, the run exists and is returned as a list; if it is a fraction, no run of that length can reach the target, and the tool says so instead of rounding to a misleading answer.
How the solver decides
The solver never iterates or approximates. It computes the remainder T − n(n−1)/2 and checks whether n divides it evenly. Divisibility is the whole decision: an even split means the first term is an integer and the run is real; a nonzero remainder means the target is unreachable with that count, full stop.
Input validation runs first: the count must be a positive integer and the target must be an integer, and anything else is rejected as invalid input before any arithmetic happens. Invalid requests are errors, not results, and they are never billed.
When to use it and what it costs
Use it whenever a puzzle, a proof exercise, or a scheduling problem asks whether a total can be split into equal consecutive steps. Teachers use it to generate worked examples; developers use it to sanity-check partitioning logic; puzzle solvers use it to settle arguments instantly. A useful fact the tool makes tangible: a target can be written as a run of consecutive positive integers exactly when it is not a power of two, and experimenting with different counts here is a fast way to build intuition for that theorem.
What you can do with it
Settle a puzzle instantly
Check whether 100 can be written as 5 consecutive integers (yes: 18–22) or as 4 (no) without trial and error.
Generate teaching examples
Produce worked consecutive-sum problems with known answers for arithmetic and algebra classes.
Validate partitioning logic
Cross-check application code that splits a total into consecutive slots, ids, or time steps against an exact solver.
FAQ
What does it cost?
The same solver runs free in your browser on this page, and error responses are never billed.
Can the integers be negative or span zero?
Yes. The first term is computed exactly, so runs like −2, −1, 0, 1, 2 are returned when they satisfy the target and count.
What counts as valid input?
The target must be an integer and the count must be a positive integer (1 or more). Anything else — fractions, zero, negative counts, non-numbers — is rejected with a clear error.
How is the answer computed?
By the closed form a = (T − n(n−1)/2) / n. If a is an integer the run a…a+n−1 is returned; otherwise no solution exists. No loops, no randomness, fully deterministic.
Which totals can be written as a sum of consecutive positive integers?
Those that are not a power of two, when the run has two or more numbers. A power of two cannot be split that way, so for it the calculator finds either no run or one that includes zero or negative numbers.
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/consecutive-integers \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"target":15,"count":3}'const res = await fetch("https://api.kit.forhosting.com/math/consecutive-integers", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"target": 15,
"count": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/consecutive-integers",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"target": 15,
"count": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/consecutive-integers", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"target":15,"count":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"target":15,"count":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/consecutive-integers", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"target": 15,
"count": 3
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.consecutive_integers",
"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.
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
It runs free on this page in your browser, and the same code answers API calls at $0.002 per request.
How the solver decides
Because the check is exact integer arithmetic, the results hold for negative targets (for T = −12 and n = 4 the tool correctly reports that no run exists, since −4 − 3 − 2 − 1 already sums to −10) and for runs that span zero, such as −2, −1, 0, 1, 2 summing to 0 with n = 5.
When to use it and what it costs
The calculator runs free in your browser on this page with the exact same code that serves the API, so what you test here is what you pay for when you automate it. API access costs $0.002 per request, with no minimums, and error responses — a bad count or an impossible target — are always free.
Technical questions
What if no run exists?
The tool returns an invalid_input error explaining that no run of that count can sum to the target. It never rounds or approximates to force an answer.