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!
 A: 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.
A: $$\begin{align}(\color{red}{n^2}+\color{blue}{3n+1})^2&=(\color{red}{n^2})^2+2\color{red}{n^2}(\color{blue}{3n+1})+(\color{blue}{3n+1})^2\\&=n^4+2(3n^3+n^2)+(3n)^2+2(3n)(1)+1^2\\&=n^4+6n^3+2n^2+9n^2+6n+1\\&=n^4+6n^3+11n^2+6n+1\end{align}$$
A: When you expand something squared, you multiply each term by each other term, so in this case you have $$\begin{aligned}(n^2+3n+1)^2&=n^2\cdot n^2 + n^2\cdot 3n+n^2\cdot 1\\&\;+3n\cdot n^2+3n\cdot3n+3n\cdot1\\&\;+1\cdot n^2+1\cdot3n+1\cdot1\\&=n^4+3n^3+n^2+3n^3+9n^2+3n+n^2+3n+1\\&=n^4+6n^3+11n^2+6n+1\end{aligned}$$
A: HINT
Let expand
$$(a+b+c)^2=a^2+b^2+c^2+2ab+2bc+2ca$$
