Maximum of $a_1 \cdot a_2 \cdots a_n$ given $a_1 + \cdots + a_n = 1000$? I am not sure what I am doing wrong in my solution to this problem:

Find positive numbers $n$ and $a_1, a_2, \dots, a_n$ such that $a_1+a_2+\dots +a_n\le 1000$ and the product $a_1a_2\dots a_n$ is as large as possible.

I have that $AM-GM$ gives us $\dfrac{a_1 + \cdots + a_n}{n} = \dfrac {1000}{n} \ge \sqrt[n]{a_1 \cdots a_n}$. Regardless of $n$, we get equality (and therefore maximum of the product) $\iff$ $a_1 = a_2 = \cdots = a_n$, so the inequality above becomes $\dfrac {1000}{n} = \sqrt[n]{a_1^n}$, or $\dfrac {1000}{n} = a_1$. To maximize $a_1$, we can take $n = 1$. But this is obviously a wrong answer. 
EDIT: This is the solution they give:

 A: What you have shown is this:
For a fixed $n$, and $a_i\in \mathbb R_{>0}$, then the maximum product is attained when $a_i=\dfrac{1000}{n}$ for all $i$.
But then the product is $\left(\dfrac{1000}{n}\right)^n$, not $\dfrac{1000}{n}$. And this product is not maximised when $n=1$; it is maximised when $n$ is about $\dfrac{1000}{e}$. (Specifically: take the two integers either side of $\dfrac{1000}{e}$, and see which of them gives a greater product.)
A: Note that when $a_1=a_2=\dots=a_n$, then $\frac{1000}n=a_1$.  But then you try to find
$$\max[a_n]$$
which is not what we are looking for.  What you want is
$$\max[(a_n)^n]=\max\left[\left(\frac{1000}n\right)^n\right]$$
You may however note that since the maximum occurs when $a_1=a_2=\dots=a_n$, then by directly using the original equations:
$$na_1=1000$$
$$a_1=\frac{1000}n$$
$$a_1\times a_2\times\dots\times a_n=(a_1)^n=\left(\frac{1000}n\right)^n$$
Which is much larger than what you initially presumed.  By taking the derivative and finding the global maximum for $n\in\mathbb N$, we find the global maximum occurs at $n\approx1000/e=367.8$, and by comparing values around it, $n=368$ is our solution, with
$$a_1=2.718281828\approx e$$
and
$$(a_1)^n=5.8614\times10^{159}$$
for $a_n\in\mathbb N$, this is merely a question of whether $a_1=2$ or some bombination of $2$ and $3$, and this is easy to check that it should be as many $3$'s as possible.
A: So, as your book suggests, we can establish that $a_i \le 4$: if we were to have $a_i > 4$, then $(a_i - 2 )(2) = a_i + (a_i - 4) > a_i$. Similarly $(a_i - 1)(1) < a_i$, so we have $a_i > 1$. Thus our $a_i$'s will all be $2$ or $3$ - which are approximately $e$, in connection with Simply Beautiful Art's answer - but $2 \cdot 2 \cdot 2 < 3 \cdot 3$ guarantees that there can be at most two $2$'s.
This is a fairly classic problem, and Art's answer can be a good starting point as to making an educated guess about the solution for the naturals.
A: Using the Lagrange's multipliers method, we have find the max of
$f(a_1,\ldots,a_n)=\prod_{i=1}^n a_i-\lambda\cdot (\sum_{i=1}^n a_i-1000)$
and hence we get a system of $n$ equations as follows:
$\frac{\partial f}{\partial a_i}=\prod_{\stackrel{j=1}{j\ne i}}^n a_j-\lambda=0$
for $i=1,\ldots,n$ plus the following extra equation for the constraint:
$\sum_{i=1}^n a_i-1000=0\qquad(*)$
In particular for $j$ and $j+1$ we have
$\frac{\partial f}{\partial a_j}=\prod_{\stackrel{i=1}{i\ne j}}^n a_i-\lambda=0$
and
$\frac{\partial f}{\partial a_{j+1}}=\prod_{\stackrel{i=1}{i\ne j+1}}^n a_i-\lambda=0$
Hence we find $a_j=a_{j+1}$ for all $j=1,\ldots, n$ and from the Equation $(*)$ it follows: $a_1=a_2=\ldots=a_n=\frac{1000}{n}$.
Hence the max is $\left(\frac{1000}{n}\right)^n$.
