assume that:
$f(x)=1+x+x^2$ and $F(x)=f(x)f(x^2)...f(x^{p-1})$
thus $F(x)=\sum\limits_{n=0}^{p(p-1)}a_nx^n$
now notice that $a_n$ is equal to the number of $(x_1,...,x_{p-1})$
wich $x_j\in {0,1,2}$
and we know that $x_1+2x_2+...+(p-1)x_{p-1}=n$
there for $|E({0,1,2})|$ is equal to the sum of $a_n$ which $n$ is divisible by $p$
assume that $\omega=\cos(\frac{2\pi}{p})+i\sin(\frac{2\pi}{p})$
it yields easyly that:
$1+\omega^j+\omega^2j+...+\omega^{(p-1)j}=\{\begin{array}{cc}p&\mbox{ if } p\mid j\\0&\mbox{ if } p\not\mid j\end{array}$
there for if we add $F(x)$ for $x=1,\omega,...,\omega^{p-1}$:
$F(1)+F(\omega)+...+F(\omega^{p-1})=p|E({0,1,2})|$
notice that $F(1)=3^{p-1}$ and also notice that if $j$ is not divisible by $p$ then:
$(1,\omega^j,\omega^{2j},...,\omega^{(p-1)j})$ is a permutation of numbers $1,\omega,\omega^2,...,\omega^{p-1}$
now with using this point for $j=3$ then we have:
$F(\omega)=F(\omega^2)=...=F(\omega^{p-1})=(1+\omega+\omega^2)...(1+\omega^{p-1}+\omega^{2(p-1)})=(\frac{1-\omega^2}{1-\omega})(\frac{1-\omega^6}{1-\omega^2})...(\frac{1-\omega^{2(p-1)}}{1-\omega^{p-1}})=1$
therefor $|E({0,1,2})|=\frac{3^{p-1}+p-1}{p}$
now assume that $g(x)=1+x^2+x^3$ and $G(x)=g(x)g(x^2)...g(x^{p-1})$
now we can use the soloution before to get that:
$|E({0,1,3})|=\frac{G(1)+(p-1)G(\omega)}{p}=\frac{3^{p-1}+(p-1)G(\omega)}{p}$
there for we most show that $1\leq G(\omega)$ and it equals only for $p=5$
now if $h(x)=x^3+x+1$ then we can say that $h(x)=(x-\lambda)(x-\mu)(x-\nu)$
wich $\mu,\lambda,\nu$ are complex numbers
and $0<x$,$0<h(x)$ and also $\lambda+\mu+\nu=0$
there for $h(x)$ has a negative real root like $\lambda$
$\mu , \nu=\bar{\mu}$ are two complex roots of $h$ with positive real parts
notice that:
$G(\omega)=\prod\limits_{j=1}^{p-1}(1+\omega^j+\omega^{3j})=\prod\limits_{j=1}^{p-1}(\omega^j-\lambda)(\omega^j-\mu)(\omega^j-\nu)=(\frac{\lambda^p-1}{\lambda-1})(\frac{\mu^p-1}{\mu-1})(\frac{\nu^p-1}{\nu-1})$
(for the last equality we used $\prod\limits_{j=1}^{p-1}(x-\omega^j)=\frac{x^p-1}{x-1}$ for $x=\lambda,\mu,\nu$)
and also $(\lambda-1)(\mu-1)(\nu-1)=-h(1)=-3$
in the other hand we have $\lambda^3+\lambda^2+1=0$
therefor for all natural numbers $k$,$\lambda^{k+3}+\lambda^{k+1}+\lambda^k=0$
and teh equality is for $\mu ,\nu$ also
now if we add these equalities and use induction we`ll have that for every natural number $r$,$\lambda^r+\mu^r+\nu^r \in \mathbb {Z}$
now assume that $G(\omega)=1$,
therefor $(\lambda^p-1)(\mu^p-1)(\nu^p-1)=-3$ and $\lambda^p,\mu^p,\nu^p$ are the roots of $m(x)=x^3-qx^2+(1+q)x+1=0$
wich $q=\lambda^p+\mu^p+\nu^p \in \mathbb{Z}$
and also $\lambda$ is the real root of $x^3+x+1=0$
and $-1<\lambda<-\frac{1}{2}$
thus if $q<0$ for $x=\lambda^p$,$0<x^3-qx^2$ and $0\leq (1+q)x$
therefor $m(\lambda^p)\not= 0$
also if $q=0$,$\lambda^p=\lambda$ and therefor $p=1$ and then again we`ll reach a contradiction
there for $1\leq q$
for all $-1\leq x\leq 0$,$q(x^2-x)$ is positive and $x^3+x+1$ is only increasing and also $\lambda^3+\lambda+1=0$
$\lambda^p$,the $x$component of point $P$,is the point that the two functions $y=x^3+x+1$ and $y=q(x^2-x)$ gathere to gether
and it bvelongs to $]-1,0[$
therefor when $p$ gets greater ($\lambda^p$ nearly reaches $0$) $q$ grows greater
for $p=5,g(\omega)=1+\omega+\omega^2=-\omega^2(1+\omega^2)$
and therefor:
$G(\omega)=\prod\limits_{j=1}^{p-1}(1+\omega^{2j})=\prod\limits_{j=1}^{p-1}(1+\omega^j)=\frac{1-(-1)^p}{1-(-1)}=1$
notice that $\lambda^5=-\lambda^2(\lambda+1)=-\lambda^2+\lambda+1$
$q=-(\lambda^2+\mu^2+\nu^2)+(\lambda+\mu+\nu)+3=5$
because:
$\lambda^2+\mu^2+\nu^2=(\lambda+\mu+\nu)^2-2(\lambda\mu+\mu\nu+\nu\lambda)=-2(\lambda\mu+\mu\nu+\nu\lambda)=-2$
therefor $5\leq q$ and $q=5$ happens only for $p=5$
we know that $6\leq q$ and $m(x)=x^3+x+1-q(x^2-x)$
$m(-1)<0$,$m(0)>0$,$m(2)<0$
and for a great enogh $x$,$m(x)>0$
therefor $m(x)=0$ has three different real roots
but these roots are $\lambda^p,\mu^p,\nu^p=\bar{\mu^p}$
and if $\mu^p \in \mathbb{R}$,then $\nu^p=\bar{\mu^p}=\mu^p$
it means that $m(x)$has a repetitive root and it would be a contradiction
there for $6>q$
therefor $q=5,p=5$ is the only way that $G(\omega)=1$
from $|E({0,1,3})|=\frac{3^{p-1}+(p-1)G(\omega)}{p}$
and that $0\leq G(\omega)$ (this inequality comes from $\bar{g(\omega^j)}=g(\omega^{p-j}$)
there for $1\leq G(\omega)$
there for:
$|E({0,1,3})|\geq |E({0,1,2})|$
and the equality happens only for $p=5$