Number Theory

Which Numbers Are Sums of Consecutive Integers?

Find out which numbers are sums of consecutive positive integers, why powers of 2 never are, and how to count every possible way.

Key takeaways

  • Every positive integer except the powers of 2 is a sum of at least two consecutive positive integers.
  • A run of k consecutive integers has a sum equal to k times its average, which forces an odd factor to appear.
  • Each odd divisor greater than 1 produces exactly one such run, so counting odd divisors counts the ways.
  • Odd primes have only one representation, as two neighboring numbers.

A positive whole number can be written as a sum of two or more consecutive positive integers exactly when it is not a power of 2. So 15 works, as 7 + 8, as 4 + 5 + 6 and as 1 + 2 + 3 + 4 + 5, while 1, 2, 4, 8, 16 and 32 never work.

There is a bonus. The number of different ways to do it equals the number of odd divisors greater than 1. This article shows where both facts come from and how to build every such sum without guessing.

Experiment first

Try the first several numbers by hand. It takes only a few minutes and shows the shape of the answer.

Number Ways found
3 1 + 2
4 none
5 2 + 3
6 1 + 2 + 3
7 3 + 4
8 none
9 4 + 5, and 2 + 3 + 4
10 1 + 2 + 3 + 4
11 5 + 6
12 3 + 4 + 5

Every odd number from 3 upward appears at once, since 2m + 1 = m + (m + 1). The missing ones so far are 1, 2, 4 and 8. A guess suggests itself, but a guess from a short table is only a starting point, as working from small cases explains.

The sum of a run

Take k consecutive integers starting at a. Pair the first with the last, the second with the second to last, and so on. Every pair has the same total.

sum = a + (a + 1) + ... + (a + k − 1)
    = k × (first + last) ÷ 2
    = k × (2a + k − 1) ÷ 2

Setting this equal to n gives the central equation:

2n = k × (2a + k − 1)

In words, the sum is the number of terms times their average. This is the same pairing idea behind the sum from 1 to 100.

Why powers of 2 fail

Look at the two factors k and 2a + k − 1. Their difference is 2a − 1, which is odd. So one of the two factors is odd and the other is even.

We need k ≥ 2, and with a ≥ 1 the second factor is at least k + 1. So both factors are at least 2. Whichever one is odd is therefore an odd number of at least 3, and it divides 2n.

An odd divisor of 2n must divide n. So if n is a sum of consecutive positive integers, n has an odd divisor greater than 1. A power of 2 has none. That settles one direction completely, for all powers of 2 however large.

Why every other number succeeds

Suppose n has an odd divisor d greater than 1, and write n = d × m. Choose d consecutive integers centered on m.

n = 15, d = 5, m = 3:     1 + 2 + 3 + 4 + 5
n = 21, d = 3, m = 7:     6 + 7 + 8
n = 70, d = 5, m = 14:    12 + 13 + 14 + 15 + 16

Because d is odd there is a middle term, and the terms to its left and right balance each other, so the average is m and the sum is d × m = n.

There is one catch. If d is large compared with m, the run starts at zero or below. Take n = 14 with d = 7 and m = 2.

−1 + 0 + 1 + 2 + 3 + 4 + 5 = 14

The −1 and the 1 cancel, and 0 adds nothing. What survives is 2 + 3 + 4 + 5 = 14, a run of positive integers. This always works: the negative terms cancel their positive mirror images, leaving a consecutive run. Its length is 2m, an even number, so it has at least two terms.

Turning an odd divisor into a run
1 Split n Write n = d × m with d odd and above 1 2 Center on m Take d consecutive integers around m 3 Check the start If every term is positive, you are done 4 Cancel Otherwise delete zero and each ± pair 5 Read the run A positive run with the same sum remains Split n Write n = d × m with d odd and above 1 1 Center on m Take d consecutive integers around m 2 Check the start If every term is positive, you are done 3 Cancel Otherwise delete zero and each ± pair 4 Read the run A positive run with the same sum remains 5

Counting every way

Each odd divisor d greater than 1 gives one run. Different divisors give different runs, and every run arises from some odd divisor, namely whichever of k or 2a + k − 1 is odd. So the count of representations with at least two terms equals the number of odd divisors of n, minus 1.

Here is the full list for 45, whose odd divisors are 1, 3, 5, 9, 15 and 45.

d m Resulting run
3 15 14 + 15 + 16
5 9 7 + 8 + 9 + 10 + 11
9 5 1 + 2 + ... + 9
15 3 5 + 6 + 7 + 8 + 9 + 10
45 1 22 + 23

Five odd divisors above 1 give five sums. In the last two rows the centered run began below zero and was trimmed by cancellation.

To count odd divisors quickly, factor n, ignore every power of 2, and multiply one more than each remaining exponent. For 45 = 3² × 5 this gives 3 × 2 = 6. The method is explained in how to count divisors.

What the count reveals

Doubling a number never changes how many ways it has, because it adds no odd divisors. So 45, 90 and 180 each have exactly five representations, though the runs themselves differ.

An odd prime has odd divisors 1 and itself, so it has exactly one representation. The prime 13 is 6 + 7 and nothing else. In fact, a number with exactly one representation is a power of 2 times a power of a single odd prime with exponent 1. For example 12 = 4 × 3 has only 3 + 4 + 5.

That gives a curious test: an odd number of at least 3 is prime exactly when its only representation as consecutive positive integers is the two-term one. It is a lovely fact and a useless test for large numbers, since checking it amounts to trial division. See primes from the ground up.

A complete worked case

Find every representation of 100. Its odd divisors above 1 are 5 and 25, so there are two.

For d = 5, m = 20, and the run is 18 + 19 + 20 + 21 + 22 = 100. For d = 25, m = 4, and the centered run goes from −8 to 16. Cancel −8 through 8 and what is left is 9 + 10 + ... + 16. Eight terms with average 12.5 give 100.

Notice the pattern in lengths. An odd divisor d gives either a run of d terms, when d is small compared with m, or a run of 2m terms, when it is large. In both cases the length is the smaller of d and 2m.

Searching by length instead

There is a second route that starts from the number of terms. Suppose you want to know whether n is a sum of exactly k consecutive positive integers. The run starting at a has sum ka + (0 + 1 + ... + (k − 1)), so you need n minus the triangular number k(k − 1)/2 to be a positive multiple of k.

For n = 100, try each k in turn. With k = 2 you need 99 to be even, which fails. With k = 5 you need 100 − 10 = 90 to be a multiple of 5, which gives a = 18. With k = 8 you need 100 − 28 = 72 to be a multiple of 8, which gives a = 9. No other length works.

You can stop early. A run of k positive integers sums to at least k(k + 1)/2, so for 100 no length beyond 13 is possible. This method needs no factoring, while the divisor method needs no trial and error. Using both on the same number is an excellent check.

It also tells you the longest run. For 45 the longest is 1 through 9. Numbers such as 45 that equal a full run starting at 1 are the triangular numbers, explored with their relatives in figurate numbers.

Seeing it as a staircase

Draw each term of a run as a row of dots, shortest on top. The result is a staircase with a flat left edge, a trapezoid shape. For this reason such sums are sometimes called trapezoidal representations.

The centering argument has a clear picture here. When there is an odd number d of rows, you can slice dots off the rows longer than the middle one and move them to the rows that are shorter. Every row becomes length m, and you have a rectangle of d by m dots. Reading the move backward turns a rectangle with an odd side into a staircase.

A power of 2 can only be arranged in rectangles whose sides are themselves powers of 2. Apart from a side of length 1, which gives a single row or a column of ones, no side is odd, so there is nothing to reshape. The picture does not replace the algebra, but it makes the role of the odd side easy to remember. Pictures as proofs have limits of their own.

What makes this a good theorem

The answer is complete in three ways. It says which numbers work, it constructs a representation whenever one exists, and it counts all of them. Many questions in number theory yield only the first of these, and some yield none.

The proof also shows a useful habit: find the equation, then ask about the parity of its factors. Because 2n = k × (2a + k − 1) always splits into one odd and one even factor, parity does almost all the work. The same move appears in many divisibility arguments.

Variations on the question

If you allow negative integers, zero and runs of a single term, the count doubles: each odd divisor of n, including 1, gives two runs, one all positive and one reaching into the negatives.

Ask instead for sums of consecutive odd numbers and you meet squares. The sum of the odd numbers from the first to the a-th is a², so a block of consecutive odd numbers sums to a difference of two squares, a² − b². A positive number is a difference of two squares exactly when it does not leave remainder 2 on division by 4.

Sums of consecutive squares or cubes are far harder, and general answers are much less tidy. Changing one word in a number theory question can move it from an afternoon's work to a research problem.

Practice

How many ways can 1000 be written? Since 1000 = 8 × 125, the odd divisors above 1 are 5, 25 and 125, so there are three. They are 198 through 202, then 28 through 52, then 55 through 70. Check the last one: 16 terms with average 62.5 make 1000.

Now find a number with exactly two representations that is smaller than 15. Look for exactly three odd divisors, which means a factor of an odd prime squared. The answer is 9.

Common questions

Does the order of the terms matter?

No. A run is determined by its first and last terms, and each run is counted once.

Is there a number with exactly any chosen count of ways?

Yes. The number 3ᵏ has k odd divisors greater than 1, so it has exactly k representations. Smaller examples usually exist using several different primes.

Written for 4Mathematics with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 59 articles in Number Theory →

Latest news on this topic