Maths & numbers

Triangular number test calculator

Check whether the input is a sum of the first k positive integers.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

The index tells how many rows a triangular dot pattern has when row sizes run from 1 up to that index.

THE FORMULAn is triangular when 8n + 1 is an odd perfect square

A worked example

55 = 1 + 2 + … + 10.

Good to know

Zero is treated as the zeroth triangular number.

Recover the triangle index from the total

A triangular number counts rows containing 1, 2, 3 and so on up to k objects. The total is k(k + 1)/2. For the default input 55, solving this equation gives k = (√(8 × 55 + 1) − 1)/2 = (21 − 1)/2 = 10. Thus 55 is the tenth triangular number.

The discriminant 8n + 1 must be an odd perfect square for a nonnegative integer index to exist. For 56 it is 449, whose square root is not an integer, so the test fails. The candidate index is a diagnostic value; only an integer candidate establishes a triangular representation.

Five rows with one through five objects form a triangle of fifteen objects5 × 6 / 2 = 15
This small example has 1 + 2 + 3 + 4 + 5 = 15 objects. The default total of 55 instead corresponds to ten rows.

Check the sum by pairing terms

The ten rows for 55 can be paired as 1 + 10, 2 + 9, 3 + 8, 4 + 7 and 5 + 6. Five pairs of 11 give 55. Pairing an increasing sequence with its reverse explains the factor of one half in k(k + 1)/2.

The Consecutive integers from a sum calculator recovers a run with a specified number of terms. A triangular number specifically uses the run starting at one. Zero is accepted here as the zeroth triangular number, corresponding to no rows. The diagram uses five rows totaling 15 so that each object is visible, while the default numerical test concerns ten rows totaling 55.

A few questions, answered

Are all squares triangular?

No. Four is a square but not triangular. Thirty-six is both because it equals 1 + 2 + … + 8.

How do I check the returned index?

Substitute the integer candidate k into k(k + 1)/2 and confirm that the result equals your input.

Find your calculator

Start typing to explore the library.