<s>[INST] How does $n^4 + 6n^3 + 11n^2 + 6n + 1 = (n^2 + 3n + 1)^2?$ C++ student here, not quite familiar with these type of expressions. Can someone explain how does this work? I'm familiar with $(a+b)^2$ etc. mathematics but this seems to be like $(a+b+c)^2$ and having searched online, the opened form for this formula doesn't look much alike. Any help will be appreciated. Thanks!
 [/INST] This uses a simple rule called distributivity. This rule says that for all numbers $a,b,c$ we have:
$$a(b+c)=ab+ac$$
and:
$$(a+b)c=ac+bc$$

Now, let's say we have some numbers $a$ $b$ and $c$ and we want to compute $(a+b+c)^2$. Using our rule, we obtain:
\begin{align*}
(a+b+c)^2 &= (a+b+c)(a+b+c)\\
&=a(a+b+c)+b(a+b+c)+c(a+b+c)\\
&=a^2+ab+ac+ba+b^2+bc+ca+cb+c^2\\
&= a^2+b^2+c^2+2ab+2bc+2ca.
\end{align*}

If we put $n^2$ for $a$, $3n$ for $b$ and $1$ for $c$ to obtain:
$$(n^2+3n+1)^2=(n^2)^2+(3n)^2+1^2+2n^2\cdot 3n+2n^2\cdot 1+2\cdot 3n\cdot 1$$
Simplifying this gives:
\begin{align*}
(n^2+3n+1)^2&=(n^2)^2+(3n)^2+1^2+2n^2\cdot 3n+2n^2\cdot 1+2\cdot 3n\cdot 1\\
&= n^4+9n^2+1+6n^3+2n^2+6n\\
&=n^4+6n^3+11n^2+6n+1
\end{align*}
as desired.
</s>