## Task 4.

Determine all natural numbers $n$ such that

$$
\frac{n^{3 n-2}-3 n+1}{3 n-2}
$$

is an integer.
## First Solution.

Assume that $\frac{n^{3 n-2}-3 n+1}{3 n-2}$ is an integer.

Then $3 n-2$ divides $n^{3 n-2}-3 n+1$, and thus divides $n^{3 n-2}-1$. Therefore, we have $n^{3 n-2} \equiv 1(\bmod 3 n-2)$.

Notice that $n$ is odd (otherwise, an even number would divide an odd number, which is impossible).

Let $p>2$ be the smallest prime that divides $3 n-2$. Clearly, $p \nmid n$. By Fermat's Little Theorem, $n^{p-1} \equiv 1(\bmod p)$. Also, $n^{3 n-2} \equiv 1(\bmod p)$.

Introduce the order of $n$ modulo $p$ - the smallest natural number $r$ such that $n^{r} \equiv 1(\bmod p)$. It is known that $n^{e} \equiv 1(\bmod p)$ if and only if $r$ divides $e$.

Thus, $r$ divides $p-1$ and $3 n-2$, and hence divides their greatest common divisor. However, since $p>2$ is the smallest prime that divides $3 n-2$, it follows that $\gcd(p-1,3 n-2)=1$, i.e., the order is $r=1$, i.e.,

$$
n \equiv 1 \quad(\bmod p)
$$

From $p \mid n-1$ and $p \mid 3 n-2$, it follows that $p \mid 1$, i.e., there is no such prime $p$.

The only possible $n$ is $n=1$, and by verification, we see that 1 is indeed a solution.