\(\left(3+x+x^2\right)^8=\sum\limits^8_{k=0}C^k_8.\left(x^2+x\right)^k.3^{8-k}\)
\(\left(x^2+x\right)^k=\sum\limits^k_{t=0}C^t_k.x^{2t}.x^{k-t}\)
\(\Rightarrow\left(3+x+x^2\right)^8=\sum\limits^8_{k=0}C^k_8.C^t_k.x^{2t}.x^{k-t}.3^{8-k}\)
\(x^2\Leftrightarrow2t+k-t=2\Leftrightarrow t+k=2\)
\(k\ge t\Rightarrow\left(k;t\right)=\left(2;0\right);\left(1;1\right)\)
\(\left(k;t\right)=\left(2;0\right)\Rightarrow he-so:C^2_8.C^0_2.3^{8-2}=20412\)
\(\left(k;t\right)=\left(1;1\right)\Rightarrow he-so:C^1_8.C^1_1.3^{8-1}=17496\)