Skip to content
Omnikalc

Polygonal numbers calculator: find the n-th number for any polygon

Enter the number of sides and the position to get the polygonal number, the next one, the sum of the first n and a test of whether a number is polygonal.

Updated on
Your inputs

Value out of range

Value out of range

Value out of range

Results

The n-th polygonal number

145

The next polygonal number
176
Sum of the first n polygonal numbers
550
Position of the tested number
12.0000
Is the tested number polygonal?
1
Yes, it is polygonal

Triangular numbers stack into a triangle, square numbers into a square, and the same idea works for any polygon. This polygonal numbers calculator takes the number of sides, a position n and a number to test to give the n-th polygonal number, the next polygonal number, the sum of the first n, the position of the tested number and whether it is a polygonal number.

How the calculation works

  • n-th s-gonal number = ((s − 2) × n² − (s − 4) × n) ÷ 2, where s is the number of sides. For s = 3 this gives the triangular numbers, for s = 4 the squares and for s = 5 the pentagonal numbers.
  • Next number is the same formula with n + 1. The gap between neighbors is (s − 2) × n + 1.
  • Sum of the first n numbers = n × (n + 1) × ((s − 2) × (2n + 1) − 3 × (s − 4)) ÷ 12.
  • Position of a tested number T = ((s − 4) + √((s − 4)² + 8 × (s − 2) × T)) ÷ (2 × (s − 2)). T is polygonal when this position is a whole number.

Example

With s = 5 sides and n = 10, the pentagonal number is (3 × 100 − 1 × 10) ÷ 2 = 145. The next one, for n = 11, is 176, and the sum of the first ten is 550. To test the number 210, the position is (1 + √(1 + 24 × 210)) ÷ 6 = (1 + 71) ÷ 6 = 12. It is a whole number, so 210 is the 12th pentagonal number.

Why it matters

Polygonal numbers are a staple of number theory, recreational math and programming exercises, and they appear in Fermat’s polygonal number theorem, which says that every positive integer is the sum of at most s polygonal numbers with s sides. The test is also a good example of solving a quadratic to invert a formula.

Good to know

The formula is valid for polygons with three or more sides and for whole positions of 1 or higher. Large positions give very large numbers, and the calculator rounds the display to whole numbers. The test of a number uses a tolerance for floating point errors, which is reliable for numbers below about a billion, the limit of the field.

The triangular numbers calculator covers the case of three sides in more detail and the arithmetic and geometric series calculator gives sums of other kinds of sequences.

Frequently asked questions

What is a polygonal number?

A polygonal number counts the dots that can be arranged in a regular polygon of a given size, with each new layer sharing sides with the one before. Triangular numbers are 1, 3, 6, 10, squares are 1, 4, 9, 16 and pentagonal numbers are 1, 5, 12, 22. They are a classic example of figurate numbers.

What is the formula for the n-th s-gonal number?

It is P(s, n) = ((s − 2) × n² − (s − 4) × n) ÷ 2. The formula grows with the square of n, and the coefficient (s − 2) ÷ 2 shows that polygons with more sides grow faster. For s = 3 the formula reduces to n × (n + 1) ÷ 2.

How can I tell whether a number is polygonal?

Solve the formula for n with the quadratic formula, and keep the positive root. If the result is a whole number, the tested number is the polygonal number at that position. If it is not, the number does not belong to that sequence.

Why do some numbers belong to several sequences?

A number can be polygonal for several values of s. For example, 36 is both a square and a triangular number, and 1 is polygonal for every s. Run the test with different numbers of sides to see which sequences contain it.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.