Understanding the triangular numbers calculator — concept and principle
This calculator gives the n-th triangular number, the previous one, the square they add up to, and tests whether any whole number is triangular, giving its position or the nearest triangular numbers. Use it for number patterns, puzzles, counting handshakes or bowling pins, and maths competitions.
How it is calculated
- Tₙ = 1 + 2 + … + n = n(n + 1) ÷ 2.
- Tₙ + Tₙ₋₁ = n².
- Test: x is triangular exactly when 8x + 1 is a perfect square, because 8Tₙ + 1 = (2n + 1)².
- Position: k = (√(8x + 1) − 1) ÷ 2. If k is not a whole number, x lies between T⌊k⌋ and the next triangular number.
The test uses exact whole-number arithmetic up to 10¹⁵.
The principle
Triangular numbers count dots arranged in a triangle with 1, 2, 3, … dots per row. Two copies of the triangle, one turned upside down, fit together into an n × (n + 1) rectangle, so twice the sum is n(n + 1). That is the trick often credited to a young Carl Friedrich Gauss adding 1 to 100. Two neighbouring triangles form a square, which is why Tₙ + Tₙ₋₁ = n². Solving x = k(k + 1)/2 for k with the quadratic formula gives the test with 8x + 1.
Worked example
Default inputs: n = 10, test number 5,050.
- T₁₀ = 10 × 11 ÷ 2 = 55.
- T₉ = 45, and 55 + 45 = 100 = 10².
- Test 5,050: 8 × 5,050 + 1 = 40,401 = 201².
- k = (201 − 1) ÷ 2 = 100, so 5,050 = T₁₀₀: yes, it is triangular.
How to read the result
Tₙ answers questions like "how many handshakes among n + 1 people?" (each pair shakes once: Tₙ) or "how many pins in a triangle with 4 rows?" (T₄ = 10). For the test, a "no" comes with the triangular numbers on either side, which shows how close the number is.
Common mistakes
- Using n² ÷ 2 instead of n(n + 1) ÷ 2.
- Counting handshakes among n people as Tₙ; it is Tₙ₋₁ = n(n − 1)/2.
- Starting the sequence at T₁ = 0; T₀ = 0 and T₁ = 1.
- Testing with a rounded square root of 8x + 1 instead of an exact check.
Frequently asked questions
What are the first triangular numbers?
1, 3, 6, 10, 15, 21, 28, 36, 45, 55.
What is the sum of 1 to 100?
T₁₀₀ = 100 × 101 ÷ 2 = 5,050.
Can a triangular number also be a square?
Yes, for example 1, 36 and 1,225. There are infinitely many.
Sources: Weisstein, E. W., "Triangular Number", Wolfram MathWorld