5.38 $P(x)$ is a polynomial of degree $3n$, such that
$$
\begin{array}{l}
P(0)=P(3)=\cdots=P(3 n)=2, \\
P(1)=P(4)=\cdots=P(3 n-2)=1, \\
P(2)=P(5)=\cdots=P(3 n-1)=0, \\
P(3 n+1)=730 .
\end{array}
$$

Determine $n$.
[Solution] Notice that when $x$ takes the values $0,1,2, \cdots, 3 n$, $P(x)-1$ cyclically takes the values $1,0,-1,1,0,-1, \cdots, 1$. Therefore, we can consider the sequence
$$
\left\{w^{n}\right\}=\left\{1, w, w^{2}, 1, w, w^{2}, \cdots\right\} \text {. }
$$

where $w=\frac{1}{2}(-1+i \sqrt{3})$ is a cube root of 1. Using $\operatorname{Im}\left(w^{n}\right)$ to denote the coefficient of $i$ in $w^{n}$, we have
$$
\begin{aligned}
& \left\{2 \operatorname{Im}\left(w^{n}\right) / \sqrt{3}\right\} \\
= & \{0,1,-1,0,1,-1, \cdots\}, \\
& \left\{2 \operatorname{Im}\left(w^{2 n+1}\right) / \sqrt{3}\right\} \\
= & \{1,0,-1,1,0,-1, \cdots\} .
\end{aligned}
$$

Therefore, when $x=0,1,2, \cdots, 3 n$, we have
$$
P(x)-1=2 \operatorname{Im}\left(w^{2 x+1}\right) / \sqrt{3} \text {. }
$$

To find a polynomial in $x$. By the binomial theorem, we have
$$
w^{2 x}=\left[1+\left(w^{2}-1\right)\right]^{x}=\sum_{k=0}^{x} C_{x}^{k}\left(w^{2}-1\right)^{k} \text {, }
$$

Thus, the right-hand side of (1) can be written as
$$
2 \operatorname{Im}\left(w \sum_{k=0}^{x} C_{x}^{k}\left(w^{2}-1\right)^{k}\right) / \sqrt{3} \text {. }
$$

Here $C_{x}^{k}=x(x-1)(x-2) \cdots(x-k+1)$ can be expanded into a $k$-degree polynomial in $x$, and when $x$ takes non-negative integer values less than $k$, $C_{x}^{k}=0$.
Consider the polynomial
$$
Q(x)=2 \operatorname{Im}\left[w \sum_{k=0}^{3 n} C_{x}^{k}\left(w^{2}-1\right)^{k}\right] / \sqrt{3},
$$

Its degree is clearly $3 n$, and when $x$ takes the $3 n+1$ values $0,1,2, \cdots, 3 n$, it is equal to (1), so we have the identity
$$
P(x)-1 \equiv Q(x),
$$

Thus, $\quad P(3 n+1)-1=Q(3 n+1)$
$$
\begin{array}{l}
\left.=2 \operatorname{Im}\left[w \sum_{k=0}^{3 n} C_{3 n+1}^{k}\left(w^{2}-1\right)^{k}\right] / \sqrt{3}\right] \\
=2 \operatorname{Im}\left[w \sum_{k=0}^{3 n+1} C_{3 n+1}^{k}\left(w^{2}-1\right)^{k}-w C_{3 n+1}^{3 n+1}\left(w^{2}-1\right)^{3 n+1}\right] / \sqrt{3} \\
=2 \operatorname{Im}\left[w\left(1+w^{2}-1\right)^{3 n+1}-w\left(w^{2}-1\right)^{3 n+1}\right] / \sqrt{3} \\
=2 \operatorname{Im}\left[w^{6 n+3}-w(i w \sqrt{3})^{3 n+1}\right] / \sqrt{3} \\
=-2 \operatorname{Im}\left[i w^{2}(i \sqrt{3})^{3 n}\right] \\
=\left\{\begin{array}{ll}
(-1)^{k} 3^{3 k} & \text { when } n=2 k, \\
(-1)^{k} 3^{3 k+2} & \text { when } n=2 k+1 .
\end{array}\right.
\end{array}
$$

Given that $P(3 n+1)-1=730-1=729$, i.e., $(-1)^{k} 3^{3 k}=3^{6}$, so $k=2$,
$n=4$