Let $p$ be a fixed odd prime. A $p$-tuple $\left(a_{1}, a_{2}, a_{3}, \ldots, a_{p}\right)$ of integers is said to be good if

(i) $0 \leq a_{i} \leq p-1$ for all $i$, and

(ii) $a_{1}+a_{2}+a_{3}+\cdots+a_{p}$ is not divisible by $p$, and

(iii) $a_{1} a_{2}+a_{2} a_{3}+a_{3} a_{4}+\cdots+a_{p} a_{1}$ is divisible by $p$.

Determine the number of good $p$-tuples.
Let $S$ be the set of all sequences $\left(b_{1}, b_{2}, \ldots, b_{p}\right)$ of numbers from the set $\{0,1,2, \ldots, p-1\}$ such that $b_{1}+b_{2}+\cdots+b_{p}$ is not divisible by $p$. We show that $|S|=p^{p}-p^{p-1}$. For let $b_{1}, b_{2}, \ldots, b_{p-1}$ be an arbitrary sequence of numbers chosen from $\{0,1,2, \ldots, p-1\}$. There are exactly $p-1$ choices for $b_{p}$ such that $b_{1}+b_{2}+\cdots+b_{p-1}+b_{p} \not \equiv 0(\bmod p)$, and therefore $|S|=p^{p-1}(p-1)=p^{p}-p^{p-1}$.

Now it will be shown that the number of good sequences in $S$ is $\frac{1}{p}|S|$. For a sequence $B=\left(b_{1}, b_{2}, \ldots, b_{p}\right)$ in $S$, define the sequence $B_{k}=\left(a_{1}, a_{2}, \ldots, a_{p}\right)$ by

$$
a_{i}=b_{i}-b_{1}+k \bmod p
$$

for $1 \leq i \leq p$. Now note that $B$ in $S$ implies that

$a_{1}+a_{2}+\cdots+a_{p} \equiv\left(b_{1}+b_{2}+\cdots+b_{p}\right)-p b_{1}+p k \equiv\left(b_{1}+b_{2}+\cdots+b_{p}\right) \not \equiv 0 \quad(\bmod p)$

and therefore $B_{k}$ is in $S$ for all non-negative $k$. Now note that $B_{k}$ has first element $k$ for all $0 \leq k \leq p-1$ and therefore the sequences $B_{0}, B_{1}, \ldots, B_{p-1}$ are distinct.

Now define the cycle of $B$ as the set $\left\{B_{0}, B_{1}, \ldots, B_{p-1}\right\}$. Note that $B$ is in its own cycle since $B=B_{k}$ where $k=b_{1}$. Now note that since every sequence in $S$ is in exactly one cycle, $S$ is the disjoint union of cycles.

Now it will be shown that exactly one sequence per cycle is good. Consider an arbitrary cycle $B_{0}, B_{1}, \ldots, B_{p-1}$, and let $B_{0}=\left(b_{1}, b_{2}, \ldots, b_{p}\right)$ where $b_{0}=0$, and note that $B_{k}=\left(b_{1}+k, b_{2}+k, \ldots, b_{p}+k\right) \bmod p$. Let $u=b_{1}+b_{2}+\cdots+b_{p}$, and $v=b_{1} b_{2}+b_{2} b_{3}+\cdots+b_{p} b_{1}$ and note that $\left.\left(b_{1}+k\right)\left(b_{2}+k\right)+\left(b_{2}+k\right)\left(b_{3}+k\right)\right)+\cdots+$ $\left(b_{p}+k\right)\left(b_{1}+k\right)=u+2 k v \bmod p$ for all $0 \leq k \leq p-1$. Since $2 v$ is not divisible by $p$, there is exactly one value of $k$ with $0 \leq k \leq p-1$ such that $p$ divides $u+2 k v$ and it is exactly for this value of $k$ that $B_{k}$ is good. This shows that exactly one sequence per cycle is good and therefore that the number of good sequences in $S$ is $\frac{1}{p}|S|$, which is $p^{p-1}-p^{p-2}$.