ForHosting KIT · Math

Polygonal number calculator

Choose the number of sides and the position in the sequence to get any polygonal number exactly: the fifth pentagonal number is 35 and the tenth square is 100. 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
S
5
N
5
You get
Polygonal
35
Name
pentagonal

The closed formula is exact in integer arithmetic—P of s and n equals n times the quantity (s minus two) times n minus (s minus four), all divided by two—so the fifth pentagonal number is thirty-five, the tenth square is one hundred, and the seventh hexagonal number is ninety-one. This capability evaluates that formula for a sides count s and a positive index n, returning the polygonal value, the formula string, and a common English name when s is a familiar polygon.

What polygonal numbers are and how the formula works

Imagine arranging unit dots so they outline and fill a regular polygon with s sides, growing layer by layer. The count after n layers is the n-th s-gonal number. For three sides you recover the triangular sequence one, three, six, ten, fifteen; for four sides the perfect squares one, four, nine, sixteen, twenty-five; for five sides the pentagonals one, five, twelve, twenty-two, thirty-five.

The general closed form unifies them all: P of s and n equals n plus (s minus two) times the triangular number of n minus one, which expands to n times ((s minus two) times n minus (s minus four)) over two. Because n and n minus one are consecutive integers, their product is always even, so the division by two is exact with only integer multiplies and adds—there is no rounding, no sampling, and no dependence on wall-clock time or random seeds.

When you need the fifth heptagonal number, send s equals seven and n equals five; when you need a large square, send s equals four and a large n within the published cap. Sibling landings in this kit may target a single polygon family such as triangular numbers alone; this page is for people who need the general s-gonal calculator in one contract.

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. When teaching, prefer paired examples: s equals three and n equals five yields fifteen (triangular); s equals four and n equals five yields twenty-five (square); s equals five and n equals five yields thirty-five (pentagonal); and s equals two or n equals zero demonstrates the hard rejection path.

Do not confuse this general s-gonal tool with a membership test that asks whether an arbitrary integer is polygonal for some n—that inverse problem is a different search intent and is out of scope here. Prefer explicit s and n over inventing a free-text polygon name field: one integer pair covers every regular polygon family without ambiguous spellings or localization issues.

Programming contest and interview prep validators

Assert candidate solutions for polygonal and figurate-number problems without reimplementing the closed formula in every language harness.

What is a polygonal number?

A figurate number that counts dots arranged in a regular s-sided polygon after n layers. Formula: P(s,n)=n*((s-2)*n-(s-4))/2 for integers s≥3 and n≥1.

Does the calculator test whether a value is polygonal?

No. It only evaluates P(s,n) for given sides and index. Membership or inverse lookup for an arbitrary integer is out of scope.

Is the polygonal number calculator free?

The browser tool is free and runs locally.

What is the formula for the n-th polygonal number?

P(s, n) = n × ((s − 2) × n − (s − 4)) / 2, where s is the number of sides and n the position. The division by 2 is always exact, so the answer is always a whole number: five sides at position five give 35.

What are the first triangular, square and pentagonal numbers?

Triangular numbers start 1, 3, 6, 10; squares start 1, 4, 9; pentagonal numbers start 1, 5, 12 and reach 35 at the fifth term. Each one counts the dots that fill the shape after one more layer.

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/math/polygonal-number

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/math/polygonal-number \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"s":5,"n":5}'
{
  "s": 5,
  "n": 5
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.polygonal_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.

Per request$0.002

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

max_s10000
max_n1000000
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.

Figurate polygonal numbers count dots that form a regular polygon with s sides: triangular numbers for three sides, squares for four, pentagonal for five, and so on for any s at least three. 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 polygonal numbers are and how the formula works

A polygon needs at least three sides, so s below three is rejected; the classical index starts at one, so n below one is rejected with invalid_input rather than inventing a signed or zero-layer extension.

How to call the API and what comes back

On success the response includes s and n as normalized integers, polygonal equal to P of s and n, formula as the closed string n times ((s minus two) times n minus (s minus four)) over two, and name as a short English label such as pentagonal when s is among the common polygons, or null otherwise. Use it from homework pipelines, programming-contest validators, interview-prep sandboxes, spreadsheet enrichment jobs, or any workflow that needs a reproducible polygonal-number evaluation without installing specialized number packages on every machine. Send a JSON body with two required integer fields. Field s is the number of sides of the polygon, at least three and at most ten thousand—aliases sides, gonal, and polygon are accepted for the same meaning. Field n is the positive index of the term you want, at least one and at most one million—aliases index, order, and term map to n. Failed validation—missing s or n, a non-integer, a fraction, a value above the published limit, s below three, or n below one—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

Because the formula is the same identity used in textbooks, students can recompute small cases by hand and match the API line by line. 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.

Homework: compute s-gonal numbers for any polygon

Give students a sides count and an index and check their hand-computed figurate value against a deterministic API or free browser result.

Teaching demos of figurate sequences across polygons

Project s, n, polygonal, formula, and name in class so learners see triangular, square, pentagonal, and general s-gonal cases in one response shape.

How is this different from a triangular number calculator?

Triangular numbers are the special case s=3. This tool accepts any s≥3 (squares, pentagonals, hexagonals, and beyond) under the general s-gonal formula.

What happens if s is below 3 or n is below 1?

The request fails with invalid_input. A polygon needs at least three sides, and the classical figurate index starts at n=1. Failed tasks are not charged.

Read the full KIT documentation →