27. (USS 1) Find all natural numbers $n$ for which every natural number whose decimal representation has $n-1$ digits 1 and one digit 7 is prime.
27. Let us denote by $A_{n}(k)$ the $n$-digit number which consists of $n-1$ ones and one digit seven in the $k+1$-th rightmost position $(0 \leq k<n)$. Then $A_{n}(k)=\left(10^{n}+54 \cdot 10^{k}-1\right) / 9$.
We note that if $3 \mid n$ we have that $3 \mid A_{n}(k)$ for all $k$. Hence $n$ cannot be divisible by 3 .
Now let $3 \nmid n$. We claim that for each such $n \geq 5$, there exists $k<n$ for which $7 \mid A_{n}(k)$. We see that $A_{n}(k)$ is divisible by 7 if and only if $10^{n}-1 \equiv 2 \cdot 10^{k}(\bmod 7)$. There are several cases.
$n \equiv 1(\bmod 6)$. Then $10^{n}-1 \equiv 2 \equiv 2 \cdot 10^{0}$, so $7 \mid A_{n}(0)$.
$n \equiv 2(\bmod 6)$. Then $10^{n}-1 \equiv 1 \equiv 2 \cdot 10^{4}$, so $7 \mid A_{n}(4)$.
$n \equiv 4(\bmod 6)$. Then $10^{n}-1 \equiv 3 \equiv 2 \cdot 10^{5}$, so $7 \mid A_{n}(5)$.
$n \equiv 5(\bmod 6)$. Then $10^{n}-1 \equiv 4 \equiv 2 \cdot 10^{2}$, so $7 \mid A_{n}(2)$.
The remaining cases are $n=1,2,4$. For $n=4$ the number $1711=29 \cdot 59$ is composite, while it is easily checked that $n=1$ and $n=2$ are solutions. Hence the answer is $n=1,2$.