4.17*. (NRP, 83). Find all values of $n \in \mathbf{N}$ for each of which there exists a permutation

$$
\left(a_{1} ; a_{2} ; \ldots ; a_{n}\right)
$$

of the numbers $0,1, \ldots, n-1$, such that all numbers

$$
a_{1}, a_{1} a_{2}, a_{1} a_{2} a_{3}, \ldots, a_{1} a_{2} \ldots a_{n}
$$

give different remainders when divided by $n$.
4.17. For $n=1$ the permutation $\left(a_{1}\right)=(0)$ satisfies the condition of the problem. For $n=4$, the permutation

$$
\left(a_{1} ; a_{2} ; a_{8} ; a_{4}\right)=(1 ; 3 ; 2 ; 0)
$$

possesses the required property. Let $n$ be a prime number. According to the Chinese "remainder theorem" (Theorem 23), for each value of $k=2, \ldots, n$ there exists a number $b_{k}$ satisfying the conditions

$$
b_{k} \equiv 0(\bmod k-1), b_{k} \equiv k(\bmod n)
$$

Let $a_{k}$ be the remainder of the division of $c_{k}=b_{k} /(k-1)$ by $n$, then

$$
b_{k}=c_{k}(k-1)=a_{k}(k-1)(\bmod n)
$$

Let $a_{i}=1$ and prove that all numbers $a_{1}, a_{2}, \ldots, a_{n}$ are distinct. Indeed, we have $a_{n}=0$ and $a_{k} \neq a_{n}$ for $k=1, \ldots, n-1$ (since $a_{n}(n-1) \equiv 0(\bmod n), a_{1}=1, a_{k}(k-1) \equiv k(\bmod n)$ for $\left.k=2, \ldots, n-1\right)$. Further, if the equality $a_{l}=a_{k}=a$ holds, where $14$ does not satisfy the condition of the problem. If $n=p^{2}$, then let $q=2 p<n$, otherwise the number $n$ can be represented as a product $p q$, where $1<p<q<n$. In both cases

$$
p q=0(\bmod n) .
$$

Suppose there exists a permutation ( $a_{1} ; a_{2} ; \ldots ; a_{n}$ ) satisfying the condition of the problem. Then

$$
a_{k} \neq 0 \text { for } k=1, \ldots, n-1 \text {, }
$$

since otherwise

$$
a_{1} \ldots a_{k} \equiv 0(\bmod n)
$$

and

$$
a_{i} \ldots a_{k} a_{k+1}=0(\bmod n)
$$

Take such values of $k, l<n$ for which $a_{k}=p, a_{l}=q$. Denote

$$
m=\max (k, l)
$$

then

$$
a_{1} a_{2} \ldots a_{m} \vdots a_{k} a_{l}
$$

therefore

$$
a_{1} a_{2} \ldots a_{m}=0(\bmod n)
$$

and

$$
a_{1} a_{2} \ldots a_{m} a_{m+1} \equiv 0(\bmod n)
$$

which contradicts the assumption. Thus, the numbers 1, 4, and all prime numbers satisfy the condition of the problem.