Problems about consecutive integers appear in algebra classes, puzzles and number theory, and the answers all come from the same few formulas. The consecutive integers calculator takes the first integer, the count and the gap to give the last integer, the sum, the average and the sum of the squares, and it finds the first integer for a target sum.
How the calculation works
- Last integer = first + (count − 1) × gap. With a gap of 1 the numbers are consecutive, and with a gap of 2 they are consecutive even or odd numbers.
- Sum = count × (2 × first + (count − 1) × gap) ÷ 2, which is the count times the average of the first and last numbers.
- Average = first + (count − 1) × gap ÷ 2, the middle of the run.
- Sum of the squares = count × first² + first × gap × (count − 1) × count + gap² × (count − 1) × count × (2 × count − 1) ÷ 6.
- First integer for a target sum = target ÷ count − (count − 1) × gap ÷ 2. If the result is not a whole number, no run of that length adds up to the target.
Example
Start at 7 with 5 integers and a gap of 1: 7, 8, 9, 10, 11. The last integer is 11, the sum is 5 × (14 + 4) ÷ 2 = 45, the average is 9 and the sum of the squares is 49 + 64 + 81 + 100 + 121 = 415. To reach a sum of 75 with 5 integers, the first one is 75 ÷ 5 − 2 = 13, so the run is 13, 14, 15, 16, 17.
Why it matters
Consecutive integers are the simplest example of an arithmetic sequence, and the formulas help with homework, with tricks such as adding the numbers from 1 to 100 and with checks in programming. Knowing the average of a run lets you add the numbers in your head.
Good to know
The formulas work for negative numbers and for a run that crosses zero. The calculator handles runs up to 1,000 numbers, and the sum of the squares gets large quickly with big starting numbers. For a sum of the first n positive integers, set the first integer to 1 and the gap to 1, which gives n × (n + 1) ÷ 2. For consecutive integers with a gap larger than 1, the term arithmetic sequence is the usual name.
Related tools
The sequence calculator lists the terms of arithmetic and geometric sequences, and the arithmetic geometric series calculator sums mixed series.