Four. (50 points) Given a prime $p>3 . a_{1}, a_{2}, \cdots$, $a_{p-1}$ is a permutation of $1,2, \cdots, p-1$, and satisfies
$$
p \mid\left(a_{1} a_{2}+a_{2} a_{3}+\cdots+a_{p-2} a_{p-1}\right) .
$$

Let the number of such permutations be $K$. Find the remainder of $K$ modulo $p(p-1)$.
Four, Answer: $p-1$.
First, note that if $a_{1}, a_{2}, \cdots, a_{p-1}$ satisfy the problem, then under modulo $p$,
$$
k a_{1}, k a_{2}, \cdots, k a_{p-1} (1 \leqslant k \leqslant p-1)
$$

all satisfy the problem.
Thus, $(p-1) \mid K$.
Therefore, we only need to show that $p \mid (K+1)$.
Define a circular permutation of a $p$-tuple $\left(b_{1}, b_{2}, \cdots, b_{p}\right)$, where $b_{1}, b_{2}, \cdots, b_{p}$ is a permutation of $1,2, \cdots, p$. Two circular permutations $\left(b_{1}, b_{2}, \cdots, b_{p}\right)$ and $\left(c_{1}, c_{2}, \cdots, c_{p}\right)$ are the same if and only if there exists a $k$ such that $b_{i} = c_{i+k}$ for all $i$ under modulo $p$.

Map each permutation $a_{1}, a_{2}, \cdots, a_{p-1}$ of $1,2, \cdots, p-1$ to a circular permutation $\left(b_{1}, b_{2}, \cdots, b_{p}\right)$, i.e., take $b_{i} = a_{i}, i \leqslant p-1, b_{p} = 0$. Thus, consider the number of circular permutations that satisfy $p \mid \sum_{i=1}^{p} b_{i} b_{i+1}$ (identical circular permutations are counted only once, and it is clear that identical circular permutations have the same value of $\sum_{i=1}^{p} b_{i} b_{i+1}$), so the number of such circular permutations is also $K$.

Represent circular permutations with points, and take a graph containing all circular permutations. If
$$
B=\left(b_{1}, b_{2}, \cdots, b_{p}\right), C=\left(c_{1}, c_{2}, \cdots, c_{p}\right)
$$

satisfy $c_{t} \equiv b_{i} + 1 (\bmod p)$ for all $i$, then draw a directed edge $B \rightarrow C$, and allow self-loops. Clearly, each point has an in-degree and out-degree of exactly 1. Hence, this graph consists of several disjoint directed cycles. Since $b_{i} \equiv b_{i} + p (\bmod p)$, the length of all cycles is divisible by $p$. Thus, all cycles are either of length $p$ or length 1.

If a point representing a circular permutation $\left(b_{1}, b_{2}, \cdots, b_{p}\right)$ satisfies $p \mid \sum_{i=1}^{p} b_{i} b_{i+1}$, then mark it as a red point. Note that when
$$
B=\left(b_{1}, b_{2}, \cdots, b_{p}\right) \rightarrow C=\left(c_{1}, c_{2}, \cdots, c_{p}\right),
$$

and $B$ is a red point, $C$ is also a red point. This is because
$$
\begin{array}{l}
\sum_{i=1}^{n} c_{i} c_{i+1} = \sum_{i=1}^{n} (b_{i} + 1)(b_{i+1} + 1) \\
= \sum_{i=1}^{n} b_{i} b_{i+1} + 2 \sum_{i=1}^{n} b_{i} + p \\
= \sum_{i=1}^{n} b_{i} b_{i+1} + p^2.
\end{array}
$$

Thus, all points on a cycle of length $p$ are either all red or all not red.

Therefore, we only need to consider the number of red points on cycles of length 1.

Note that if a point $B=\left(b_{1}, b_{2}, \cdots, b_{p}\right)$ is on a cycle of length 1, then there exists a $k$ such that
$$
b_{i+k} \equiv b_{i} + 1 (\bmod p),
$$

thus, $b_{i} \equiv c i + d (\bmod p) (c, d \in \mathbf{N})$. Note that different values of $d$ result in the same circular permutation, so we can assume $d=0$.
Hence, $b_{i} \equiv c i (\bmod p)$, where $c=1,2, \cdots, p-1$.
Since different values of $c$ result in different circular permutations (consider the difference between adjacent numbers), and in this case,
$$
\begin{array}{l}
\sum_{i=1}^{p} b_{i} b_{i+1} \equiv c^2 \sum_{i=1}^{p} i(i+1) \\
= \frac{p(p+1)(p+2) c^2}{3} \equiv 0 (\bmod p),
\end{array}
$$

thus, each point on a cycle of length 1 is a red point, and there are exactly $p-1$ such points; other red points can be divided into several groups, each containing $p$ points.

Therefore, the number of such circular permutations is congruent to $p-1$ modulo $p$, so the number of permutations $K$ satisfies $p \mid (K+1)$.
Combining the above two aspects, we get $K$ modulo $p(p-1)$ is $p-1$.