Find the the coefficient of $\,x^r\,$ in $\,(1+x+x^2)^n$ I want to be able to explicitly write it as $a_r = \dots $
When using multinomial theorem, I'm getting stuck at 2 conditions, but I'm not able to simplify from there.
I wrote $(1+x+x^2)^n =\displaystyle \sum_{a,b,c}^{a+b+c=n}\frac{n!}{a!b!c!}(1)^a(x)^b(x^2)^c = \frac{n!}{a!b!c!}x^{b+2c} $
so my conditions are $b+2c=r$ and $a+b+c=n$, how do I proceed from here?
Edit: Since in this particular case, we are able to write $
(1+x+x^2)^n = \displaystyle(\frac{1-x^3}{1-x})^n$, how can we do it for any random multinomial like $(1+3x+7x^2)^n $?


$\,x^r\,$ in $\,(1+x+x^2)^n$

I see a combinatorics way, notice the zero set consists of $\omega$ and $\omega^2$ repeated $n$ times. Coefficient of $x^r=x^{2n-p}$ for some $p \in \mathbb{N}$. Now, this coefficient by Vieta's theorem is sum of all the ways we can take roots $p$ at a time with a minus power:
$$ \text{coeff} = ( \text{roots taken p at a time} )(-1)^p$$
Suppose we take $t$ copies of $\omega$ then we take $p-t$ copies of $\omega^2$, the contribution to the choice to the coefficient is:
$$ (-1)^p \binom{n}{t}  \omega^t \binom{n}{p-t} \omega^{2p-2t}$$
This simplifies into:
$$ (-1)^p \omega^{-t+ 2p} \binom{n}{t} \binom{n}{p-t}$$
To get the total coefficient, we have to add up the terms:
$$ \text{coeff} = \left[ \sum_{t=0}^p \omega^{-t} \binom{n}{t} \binom{n}{p-t}\right] 
 \omega^{2p} (-1)^p $$

Sanity check:
Suppose $n=1$,$r=1$ and $p=1$ then:
$$ \text{coeff}= \sum_{t=0}^1 \left[  \omega^{-t} \binom{1}{t}^2 \right] \omega^{2} (-1)^p=1$$
