Henry Lee

Generalizing a Math Problem

February 24, 2025

Consider the following problem:

Find 3 distinct positive integers that add up to 3n and have the maximum product.
n+
-- Singapore Mathematical Olympiad, 2005

If the integers are non-distinct, the 3 integers are {n,n,n}, due to the AM-GM inequality.

For 3 real numbers a,b,c0,

a+b+c3abc3


with equality if and only if a=b=c.

Intuitively, the integers should be as close to each other as possible for the maximum product if they have the same sum.

For a pair of integers, this can be proven by the quadratic equation:

4bc=(b+c)2(bc)2where b,c+,bc

So |bc| must be minimized for bc to be maximized. Also,

b+c is odd|bc| is oddb+c is even|bc| is evenb+c=bc+2c2c is even


Which makes the minimum difference between 2 consecutive integers 1 if their sum is odd, and 2 if their sum is even.

Alternatively, it might be easier to visualize by considering the odd and even cases separately.
Sum is odd:

b+c=2x+1,x+x(x+1)=x2+x(x1)(x+2)=x2+x2(x2)(x+3)=x2+x6 

Sum is even:

b+c=2x,x+x×x=x2(x1)(x+1)=x21(x2)(x+2)=x24

So for 3 integers, a<b<c, the difference between a and b is either 1 or 2, and the difference between b and c is either 1 or 2.
We can manually check each possible permutation:

(n1)×n×(n+1)=n3n(n2)×n×(n+2)=n34n(n1)+n+(n+2)=3n+13n(n2)+n+(n+1)=3n13n{n1,n,n+1} are the 3 distinct integers

#Generalizing the problem

Hmm, is there a better way than manually checking every possible permutation?

Can we solve the generalized problem:

Find m distinct positive integers that add up to mn and have the maximum product.
n,m+

If we were to manually check each permutation, we would have to check 2m1 permutations!

Lemma: There can be at most 1 pair of consecutive integers with a difference of 2.

Let the m distinct integers be a1,a2,...,am where a1<a2<...<am. There can only be at most one i where ai+1ai=2 and 1i<m. For every other j where 1j<m and ji, aj+1aj=1.

Suppose there are 2 distinct pairs of consecutive integers with ai+1ai=2 and aj+1aj=2 where 1<i<j<m. Let ai=x, ai+1=x+2, aj=y, aj+1=y+2.

Consider the pair ai=x and aj+1=y+2.
The current difference is aj+1ai=y+2x.
Keeping the sum the same at ai+aj+1=x+y+2, we can change ai to x+1 and aj+1 to y+1.
The new difference is aj+1ai=yx<y+2x.
Since the new difference is smaller, the new product aiaj+1 is larger.
With the new changes, ai+1ai=1 and aj+1aj=1.

Hence, the sequence cannot have 2 pairs of consecutive integers with a difference of 2, so it has at most 1 pair of consecutive integers with a difference of 2 (with all other pairs of consecutive integers having a difference of 1).

We can enumerate all such unique sequences, and show that the sum is strictly increasing by 1 and hence unique.

If there exists a pair of consecutive integers that has a difference of 2, and we can add 1 to the first integer in that pair.
Else, we can add 1 to the last integer to create a pair with a difference of 2.

1,2,...,m2,m1,msum0=m(m+1)21,2,...,m2,m1,m+1sum1=sum0+11,2,...,m2,m,m+1sum2=sum0+22,3,...,m,m+1summ=sum0+m2,3,...,m,m+2summ+1=sum0+m+1
Let sumx=mnx=mnm(m+1)2x=m(m+1)2+m(nm1)Let pxm(m+1)2modmp=0ai+1ai=1 for i=1,2,3,...(n1)p>0 ap+1ap=2First term of the sequence, a0=xm+1=m+12+nm

If m is odd:

m+12+,m2∉+ pxm(m+1)20modm Every pair of consecutive integers has a difference of 1 a0=xm+1=m+12+nm=nm12 Solution for odd m={nm12,nm12+1,...n+m121,n+m12}

If m is even:

m+12∉+,m2+ pxm(m+1)2m(m2)+m2m2≢0modm Only the pth pair of consecutive integers has a difference of 2 ap+1ap=2 a0=xm+1=m+12+nm=nm2 Solution for even m={nm2,nm2+1,...n1,n+1,...n+m21,n+m2}

#Generalizing the solution further

Surprisingly, we can use the solution to solve the much more general problem:

Find m distinct positive integers that add up to s and have the maximum product.
m,s+,sm(m+1)2

Similarly,

p=0ai+1ai=1 for i=1,2,3,...(n1)p>0 ap+1ap=2

If m is odd:

psmodmFirst term of the sequence, a0=smm12

If m is even:

ps+m2modmFirst term of the sequence, a0=smm2

#Credits

Massive thanks to Joel Yip for helping with the problem and solution!


henrlly [at] icloud [dot] com
github.com/henrlly
linkedin.com/in/henrlly
RSS