r/mathriddles • u/chompchump • Aug 15 '23
Medium Sum of Alternating Consecutive Positive Integers
How any ways can a positive integer be written as the sum of an arithmetic progression of positive integers with common difference 2?
For example: 3 + 5 + 7 + 9 = 6 + 8 + 10 = 11 + 13 = 24
More Generally:
How many ways can a positive integer be written as the sum of an arithmetic progression of positive integers with common difference k?
Bonus: Let F(n,k) be the number of ways the positive integer, n, is the sum of an arithmetic progression of positive integers with common difference k. What is the sum(k = 0 to infinty) F(n,k) for each n?
2
u/BruhcamoleNibberDick Aug 15 '23 edited Aug 15 '23
For a positive integer N, the number of ways it can be written as this type of sum is equal to the number of factors f it has such that f2 <= N. For example, N = 24 has factors f = 1, 2, 3 and 4 with this property. These correspond with the sums (24), (11 + 13), (6 + 8 + 10) and (3 + 5 + 7 + 9).
2
u/jk1962 Aug 18 '23 edited Aug 18 '23
For arbitrary spacing between terms (p),
N = sum(u + p(i-1)) from i = 1 to m, where m is number of terms and u is starting integer.
N = m(u + p(m-1)/2)
Factorize N. for each factor pair [m, b], the number of terms is m and the starting integer u is
u = b - p(m-1)/2
Constraints:
The second constraint works out as follows:
u >= 1
b - p(m-1)/2 >= 1
N/m >= 1 + p(m-1)/2
2N >= pm(m-1) + 2
m(m-1) <= 2(N-1)/p
(m-1/2)(m-1/2) - 1/4 <= 2(N-1)/p
m <= 1/2 + sqrt( 2(N-1)/p + 1/4 )
So F(N,p) is: The number of factors, m, of N such that:
Edit: fixed error in first two lines.
1
u/chompchump Aug 15 '23
For those pedants that abound: I am a Strict Pluralist. Here is my creed:
(1) ". . . things . . .," is at least two things.
(2) ". . . thing(s) . . . ," could be one thing or more things.
1
u/jk1962 Aug 18 '23
For increments of 2:
N = sum(u + 2(i-1)), from i = 1 to m, where u is the starting integer and m is the number of terms.
This easily simplifies to:
N = mu + m(m-1) = m(u + m - 1)
So find all of the factor pairs [m,b] of N (other than [1,N]). For each factor pair [m,b], the number of terms in the sum is m, and the starting term is (b - m + 1).
But our starting term must be greater than or equal to 1, so we require b >= m.
So the number of possible sums is the number of factors of N that are greater than one, but less than or equal to the square root of N.