If $a + b = 20$, then what is the maximum value of $ab^2$? Knowing that
$$a + b = 20$$
and $a,b \in \mathbb{Z}_{+}$
What is the maximum value that $ab^2$ can take?
If $b$ is even then so is $a$. Hence, let $b = 2k$ and $a = 20 - 2k$, where $k \in \{1, 2, 3, \cdots, 9\}$
$$ab^2 = (20 - 2k)(2k)^2 = 80k^2 - 8k^3$$
The value of $k$ which maximizes $ab^2$ is therefore $k = 7$ which gives $ab^2 = 1176$.
However this only shows that this is the maximum for even values of $a$ and $b$. It turns out that the maximum of $ab^2$ is when both are odd. 
How do I solve this question since my approach is clearly not very elegant? 
My solution:
$$a = 20 - b \Longrightarrow ab^2 = (20 - b)b^2$$
Differentiate to find the maximum value of $b$
$$40b - 3b^2 = b(40-3b) = 0$$ 
$$\Longrightarrow b = \left\lfloor \frac{40}{3} \right\rfloor$$ $$\Longrightarrow b = \left\lceil \frac{40}{3} \right\rceil$$
Therefore $a, b = 7, 13$ or $a, b = 6, 14$. Inspecting these $2$ cases yields the former.
So the maximum value $ab^2$ can take is $1183$.

Comment: Let $p = ab^2.$ For integers, it is neither imaginative nor difficult to try all possibilities:
   a  b    p
   1 19  361
   2 18  648
   3 17  867
   4 16 1024
   5 15 1125
   6 14 1176
   7 13 1183  # <-----
   8 12 1152
   9 11 1089
  10 10 1000
  11  9  891
  12  8  768
  13  7  637
  14  6  504
  15  5  375
  16  4  256
  17  3  153
  18  2   72
  19  1   19

