Pentagonal number calculator
The 5th pentagonal number is 35, from n(3n − 1)/2. Enter an index to get its pentagonal number, or enter any whole number to find out whether it belongs to the sequence and at which position. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 5
- Power (W)
- 35
Pentagonal numbers are the figurate sequence that counts dots arranged in nested regular pentagons. The closed formula is simple and exact: the n-th pentagonal number equals n times three-n-minus-one, all over two. That identity produces the familiar list 0, 1, 5, 12, 22, 35, 51, and so on for non-negative indexes. This calculator both evaluates P(n) for a chosen index and tests whether an arbitrary non-negative integer is a member of the sequence, using the classical discriminant condition rather than a slow search. Negative indexes are rejected with a clear validation error so callers never confuse this tool with generalized pentagonal numbers used in partition theory.
What pentagonal numbers are and how P(n) is defined
A pentagonal number counts the dots you would draw if you built successive regular pentagons that share a vertex and grow by one ring at a time. The geometric story is the same family as triangular and square numbers: each figurate sequence has a simple polynomial that turns the ring index into a count of dots. For pentagons the polynomial is P(n) = n(3n − 1) / 2.
Substituting small non-negative integers recovers the standard table: P(0) = 0, P(1) = 1, P(2) = 5, P(3) = 12, P(4) = 22, P(5) = 35, P(6) = 51, P(7) = 70, P(8) = 92, P(9) = 117, P(10) = 145. The formula always yields an integer for integer n because either n or 3n − 1 is even, so division by two is exact in integer arithmetic.
Contests, Project Euler style problems, and discrete-mathematics courses use these values constantly: for example, the well-known search for numbers that are both triangular and pentagonal depends on evaluating the formula repeatedly and on testing membership without building huge lists. Understanding that P(n) is a quadratic, not a recurrence you must iterate, is the first step to using the sequence confidently in code and on paper.
How this calculator computes P(n) and tests membership
Send at least one of two fields. The integer field n asks for the n-th pentagonal number under the closed form above; the engine validates that n is present as a finite integer, non-negative, and within the published upper bound, then returns p equals n times three-n-minus-one over two together with the formula string for documentation. The integer field value asks a different question: is this number somewhere in the pentagonal sequence?
Membership does not loop from one upward. Instead it uses the inverse of the quadratic: value is pentagonal if and only if one plus the square root of one plus twenty-four times value, all divided by six, is a non-negative integer. The implementation checks that discriminant with an integer square root so floating-point rounding never falsely accepts or rejects a candidate.
When the test succeeds, the response also returns the matching index k such that P(k) equals value. You may supply both fields in one request; each path is independent.
What you can do with it
Homework and contest verification
Students and graders confirm P(n) for a given index and test whether a listed integer is truly pentagonal without a local computer-algebra system.
Project Euler and search filters
Scripts that hunt for numbers that are triangular, square, and pentagonal can call a deterministic membership oracle instead of rebuilding sequences in every language.
Teaching figurate-number formulas
Lesson pages that introduce P(n)=n(3n−1)/2 can show the closed form beside the inverse discriminant so learners connect geometry to algebra.
FAQ
What happens if n is negative?
Only non-negative indexes are accepted; negative n is rejected and not charged.
Is the pentagonal number calculator free?
The browser tool runs free on your device.
Why is membership not a linear search?
The inverse of P(n) is an exact quadratic test: (1+sqrt(1+24x))/6 must be a non-negative integer. This calculator checks that with integer arithmetic in constant time.
How do I check whether a number is pentagonal?
Enter it as the value to test. It is pentagonal when 1 plus the square root of 1 plus 24 times the value, all divided by 6, gives a whole number; for 35 the test lands on position 5.
Why is n(3n − 1)/2 always a whole number?
Because either n or 3n − 1 is even, so the product always divides exactly by 2. The division never leaves a remainder, whatever index you choose.
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/pentagonal-number \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5}'const res = await fetch("https://api.kit.forhosting.com/math/pentagonal-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/pentagonal-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/pentagonal-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/pentagonal-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.pentagonal_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 | 10000000 |
max_value | 150000000000000 |
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
How this calculator computes P(n) and tests membership
Negative n fails immediately with invalid_input and is not charged. Missing both fields, non-integers, and values above the published limits all fail with invalid_input.
Practical use, limits, pricing, and delivery
Use the browser tool when you want an immediate P(n) or a yes-or-no membership check while studying figurate numbers, checking a contest answer, or explaining the discriminant test without installing a computer-algebra system. Accepted indexes run from zero through ten million and membership candidates up to one hundred fifty trillion so large teaching demos and Project-Euler-scale filters remain feasible without unbounded memory growth. There is no language model, no external arithmetic service, and no randomness, so the capability is safe to pin in continuous-integration checks and reproducible lesson materials. Each successful request is one billable item at $0.002; failed validation does not consume balance. Results are fully deterministic: the same n always yields the same p, and the same value always yields the same is_pentagonal flag and index. Wire the endpoint into number-theory demos, coding-interview sandboxes, discrete-math tutorials, or integer preprocessing steps where you already prefer exact figurate arithmetic over approximate heuristics or opaque black-box calculators that cannot show the formula or the membership proof.
Technical questions
How do I compute the n-th pentagonal number with this API?
Send a JSON body with non-negative integer field n to math.pentagonal_number. The response returns p = n*(3*n-1)/2 and the formula string.
How do I test whether a number is pentagonal?
Send field value with the candidate integer. The response sets is_pentagonal and, when true, index equal to the k such that P(k)=value.