MathsNumber Theory

Number Sequence
calculator.

List the terms and sums of triangular, square, prime, Fibonacci and other sequences.

How it's worked out

Pick a family of numbers and how many terms you want. Each family has a rule for term n and, for most, a rule for the sum of the first n terms. Whole-number families are worked out exactly, with no rounding at any size.

Triangular numbers count dots in a triangle: 1, then 1 + 2, then 1 + 2 + 3, and so on. OEIS A000217 gives the rule below, so the 10th is 55. Adding up the triangular numbers gives the tetrahedral numbers, the count of balls in a triangular pyramid.

T(n)\displaystyle T(n)=n(n+1)2\displaystyle {}= \frac{n(n+1)}{2}
T(1)+T(2)+⋯+T(n)\displaystyle T(1) + T(2) + \cdots + T(n)=n(n+1)(n+2)6\displaystyle {}= \frac{n(n+1)(n+2)}{6}

Cubes add up to a square. The first n cubes always add to the square of T(n). The first 10 cubes add to 3,025, which is 55 squared. A pentagonal number is a square with a triangle on top, so P(6) is 36 plus T(5) = 15, which makes 51.

13+23+⋯+n3\displaystyle 1^{3} + 2^{3} + \cdots + n^{3}=T(n)2\displaystyle {}= T(n)^{2}

Fibonacci and Lucas numbers follow the same rule, each term the sum of the two before it, but start differently. Fibonacci runs 1, 1, 2, 3 and Lucas runs 2, 1, 3, 4. Their sums have a short cut: the first 12 Fibonacci numbers add to F(14) − 1, which is 376, and the first 10 Lucas numbers add to 198.

Primes have no rule for term n. The tool sieves for them: it crosses out every multiple of 2, 3, 5 and so on up to a limit. For 100 primes it sieves up to 614 and finds 112, then keeps the first 100. Prime number 100 is 541. OEIS A000040 notes that the nth prime grows like n times the natural log of n.

Arithmetic and geometric sequences take your own first term and step. An arithmetic one adds the same difference d each time, and a geometric one multiplies by the same ratio r. OpenStax College Algebra gives the sum rules, and an endless geometric sum settles only when r is between −1 and 1.

an\displaystyle a_{n}=a1+(n−1)d\displaystyle {}= a_{1} + (n-1)\,d
Sn\displaystyle S_{n}=n(a1+an)2\displaystyle {}= \frac{n\,(a_{1} + a_{n})}{2}
Sn\displaystyle S_{n}=a1(1−rn)1−r\displaystyle {}= \frac{a_{1}\,(1 - r^{n})}{1 - r}

Worked examples

Ivan stacks cans for a store display

Ivan builds a flat triangle of cans against a wall, 10 rows high, with one can on top. That takes T(10) = 55 cans.

Next week he wants a free-standing pyramid, 10 layers deep, each layer a triangle. That is the sum of the first 10 triangular numbers, 220 cans, and it matches the 10th tetrahedral number, 220.

Open this example in the tool

A ball that bounces to half its height

In a physics model, a ball falls 1 m and each bounce reaches half the height of the one before. The drops form a geometric sequence with a first term of 1 and a ratio of 0.5. The 10th drop is 0.001953125 m.

The first 10 drops add to 1.998046875 m. Because the ratio is between −1 and 1, the total never passes 2 m, however many bounces you count. Real balls lose a different share of height each time, so treat the model as a first guess.

Open this example in the tool

Is 5,050 a triangular number?

A puzzle asks for the total of the whole numbers from 1 to 100. That total is a triangular number, and looking up 5,050 shows it is term 100.

So the list of 100 triangular numbers ends at 5,050. A number that is not triangular gets its neighbors instead: 50 falls between 45 and 55.

Open this example in the tool

Reading your result

Every list starts at term 1 except Lucas. The Lucas list follows the OEIS and starts at L(0) = 2, so its 10 terms run from L(0) to L(9). The same shift explains why its sum rule uses L(n + 1).

Two neighbors make a square. T(9) and T(10) are 45 and 55, and together they make 100, which is 10 squared. Fitting two dot triangles together into a square shows why this always works.

Long terms stay exact. The 500th Fibonacci number has 105 digits and the 500th power of 2 has 151, and both are given to the last digit. The answer shows long numbers to 5 significant figures, and the table and export carry every digit.

Your own sequences use decimals. Arithmetic and geometric terms are rounded to 12 significant figures to clear the tiny errors decimals pick up. The first 10 odd numbers, from a first term of 1 and a difference of 2, end at 19 and add to 100.

Common mistakes

  • Using n instead of n − 1. Term 1 has had no steps added, so term n has n − 1 of them. Writing a₁ + n × d lands one term too far.
  • Dividing by zero when r = 1. The geometric sum rule divides by 1 − r. When every term is the same, just multiply: 4 terms of 5 add to 20.
  • Adding an endless geometric sequence that grows. With r = 2 the terms double for ever, so there is no sum to infinity at all.
  • Counting 1 as a prime. A prime has exactly two divisors, so the list starts at 2.
  • Mixing up the index of Lucas numbers. L(0) = 2 and L(1) = 1, so the 10th term in this list is L(9), not L(10).

Questions people ask

There are exact formulas, such as one built on Wilson's theorem, but they test every number up to the answer and are slower than a sieve. No polynomial can give the nth prime. In practice the nth prime is found by sieving, and n times the natural log of n gives its rough size.

Sources