2. Given positive integers $n$ and $a_{1}, a_{2}, \cdots, a_{n}$ such that $a_{1}+a_{2}+\cdots+a_{n}=1996$, and the product is maximized. Then $n=$ $\qquad$
2. 665 or 666.

Because
$$
2(a-2)>a(a \geqslant 5)
$$
$$
\begin{array}{l}
3 \times 3>2 \times 4 \\
3 \times 3>2 \times 2 \times 2 \\
3 \times 3 \times 2>4 \times 4 \\
a+1>a \times 1 \text { ( } a \text { is a positive integer) }
\end{array}
$$

Therefore, under the premise that $a_{1}+a_{2}+\cdots+a_{n}$ is constant, to maximize $a_{1} a_{2} \cdots a_{n}$, $a_{1}, a_{2}, \cdots, a_{n}$ cannot contain 5 or any number greater than 5 (otherwise, by (1), 2 and 2- $a$ can replace $a$). Similarly, by (4), there can be at most one 4, by (3) there can be at most two 2s, by (5) there cannot be 1, and by (2) 2 and 4 cannot coexist.

Thus, $a_{1}, a_{2}, \cdots, a_{n}$ can either have two 2s, one 2, or one 4, with the rest being 3s.

Since $1996=665 \times 3+1=664 \times 3+4=664 \times 3+2$ +2,
so $a=665$ or 666.