When is the number $11111\cdots1$ a prime number?
For which $n$ is the sum: $$\sum_{k=0}^{n}10^k$$ a prime number? Are they finite?
Solution 1:
After adding $1$, the $n$s for which the sum above is known to be prime or probably prime are given in the OEIS sequence A004023. (The $+1$ is because the OEIS lists numbers $n$ such that $(10^n-1)/9$ is prime, but the sum in the question is instead equal to $(10^{n+1}-1)/9$.) Also, see the Wikipedia article and the Prime Pages entry.
These primes are called "repunit primes" since their decimal expansion consists of a repeated series of $1$s. The repunits corresponding to $$ n=1, 18, 22, 316, \text{and } 1030 $$ $$\text{ (using the $n$ in the questioner's formula above)} $$ are known to be prime. The repunits corresponding to $$ n=49080, 86452, 109296, \text{and } 270342 $$ $$\text{ (again using the $n$ in the questioner's formula above)} $$ are as far as I know only known to be probably prime.
The obvious factorization $$ \frac{10^{km}-1}{9}=\frac{10^k-1}{9}(1+10^k+\cdots+10^{k(m-1)}) $$ means that, for $(10^{n+1}-1)/9$ to be prime, $n+1$ must also be prime.
There are conjectured to be infinitely many repunit primes.
Solution 2:
Partial solution:
Given a prime $p \neq 2, 5$, let $n = Q(p - 1) + R$. We use Fermat's Little Theorem modulo $p$:
$$\begin{align} \sum_{k = 0}^n10^k &= 1 + \sum_{i = 1}^Q10^{(i - 1)(p - 1)}(10^1 + 10^2 + \dotsb + 10^{p - 1}) + 10^{Q(p - 1)}(10^1 + 10^2 + \dotsb + 10^R)\\ &\equiv 1 + \sum_{i = 1}^Q\frac{p(p - 1)}{2} + (10^1 + 10^2 + \dotsb + 10^R)\\ &\equiv \sum_{k = 0}^R10^k \pmod{p}. \end{align}$$
The $p(p - 1)/2$ came from the fact that the residues of $10^1, 10^2, \dotsc, 10^{p - 1}$ modulo $p$ form a permutation of $1, 2, \dotsc, (p - 1)$.