12. (IMO-31 Shortlist) Find all natural numbers $n$, such that every natural number represented in decimal notation with $n-1$ digits 1 and one digit 7 is a prime number.
12. A natural number $N$ composed of $n-1$ ones and one 7 can be expressed as
$N=A_{n}+6 \cdot 10^{k}$, where $A_{n}$ is a natural number composed of $n$ ones, and $0 \leqslant k \leqslant n$.
When $3 \mid n$, the sum of the digits of $A_{n}$ is divisible by 3, so
$3 \mid A_{n}$.
Thus, $3 \mid N$.
Since $N>3$, $N$ is not a prime number.
Now consider the case of $3 \times n$.
By Fermat's Little Theorem, we have
$$
\begin{array}{l}
\left(10^{6}\right)^{t} \equiv 1(\bmod 7), \\
10^{6 \prime} \equiv 1(\bmod 7) .
\end{array}
$$

Thus, $A_{6 t+s} \equiv A_{6 t}+A_{s} \cdot 10^{6 t} \equiv A_{6 t}+A_{s} \quad(\bmod 7)$.
Note that
$10^{\circ} \equiv 1(\bmod 7), 10^{1} \equiv 3(\bmod 7), 10^{2} \equiv 2(\bmod 7) ，$
$10^{3} \equiv 6(\bmod 7), 10^{4} \equiv 4(\bmod 7), 10^{5} \equiv 5(\bmod 7)$.
Also,
$A_{1} \equiv 1(\bmod 7), A_{2} \equiv 4(\bmod 7), A_{3} \equiv 6(\bmod 7)$,
$A_{4} \equiv 5(\bmod 7), A_{5} \equiv 2(\bmod 7), A_{6} \equiv 0(\bmod 7)$,
Therefore, if and only if $6 \mid n$,
$A_{n} \equiv 0(\bmod 7)$.
Thus, when $6 \times n$,
$A_{n} \equiv r \neq 0(\bmod 7)$.
Therefore, when $6 \times n$, there must exist a $k, 06$ such that
$N=A_{n}+6 \cdot 10^{k} \equiv r+(7-r) \equiv 0(\bmod 7)$.
At this point, $N$ is not a prime number.
Finally, consider the cases when $n=1,2,4,5$.
When $n=1$, $N=7$ is a prime number;
When $n=2$, $N=17,71$ are prime numbers;
When $n=4$, $1711=29 \cdot 59$ is not a prime number;
When $n=5$, $11711=11111+6 \cdot 10^{2} \equiv 0(\bmod 7)$, i.e., $11711=7 \cdot 1673$ is not a prime number.
Therefore, the only values of $n$ that satisfy the problem are $n=1,2$.