Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say we have a value $K$. I want to find the value where $A+B = K$ (all $A,B,K$ are integers) where $AB$ is the highest possible value.

I've found out that it's:

  • $a = K/2$; $b = K/2$; when $K$ is even

  • $a = (K-1)/2$; $b = ((K-1)/2)+1$; when $K$ is odd.

But is there a way to prove this?

share|cite|improve this question
I think $n=K$ is an integer and also you seem to want $A,B$ to be integers. If these guesses are right, you should edit the question to make these clear. – Dinesh Feb 6 '11 at 8:55
Thanks dinesh, I've changed it. – Timo Willemsen Feb 6 '11 at 8:57
up vote 3 down vote accepted

In the even case, assuming $A\leq B$, the numbers will be of the form $A=\frac{K}{2}-m$ and $B=\frac{K}{2}+m$ in order to get $A+B=K$, with $m=0,1,\ldots,\frac{K}{2}$. Then multiplying gives $AB=\left(\frac{K}{2}\right)^2 - m^2 \leq \left(\frac{K}{2}\right)^2$.

In the odd case, you'll have $A=\frac{K}{2}-m-\frac{1}{2}$ and $B=\frac{K}{2}+m+\frac{1}{2}$, with $m=0,1,\ldots,\frac{K-1}{2}$. Multiplying gives

$\begin{align*} AB &= \left(\frac{K}{2}\right)^2 - \left(m+\frac{1}{2}\right)^2 = \frac{K^2}{4} - m^2 - m - \frac{1}{4} \\ & = \frac{K-1}{2}\left(\frac{K-1}{2}+1\right) - m^2 - m \leq \frac{K-1}{2}\left(\frac{K-1}{2}+1\right). \end{align*}$

Alternatively, you can think of optimizing a quadratic function by finding the vertex. If you write $AB$ as a quadratic function of $A$ or $B$ alone using the constraint $A+B=K$ (as indicated in PEV's answer), then the closest integer to the vertex will solve your problem because the parabola opens down.

share|cite|improve this answer

We know that $B = K-A$. So you want to maximize $AB = A(K-A)$. So we have:

$$AB = A(K-A)$$

$$ = AK-A^2$$

Find the critical points and use some derivative tests.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.