Let $b_i = \dfrac{a_1a_2 \ldots a_n}{a^2_i}$. We take the polynomial $(X - b_1)(X-b_2) \ldots (X-b_n)$. This polynomial has degree $n$, is monic and has $n$ rational roots $b_1, b_2 \ldots b_n$. If we prove that all coefficents of the polynomial are integers, we are done, because in this case all $b_1, b_2 \ldots b_n$ must be integers. We are given that the coefficient of $X^{n-1}$ is an integer, and for other coefficents, the power of $a_i$ in the numerator is $\ge 2$ and the power of $a_i$ in the denominator is either $0$ or $2$. Hence $a^2_i$ should divide $a_1a_2 \ldots a_n$, for each $1\le i \le n$.