What is the largest prime $p$ such that the decimal expansion of $1/p$ repeats with period 2017? By this discussion on John Baez's Google+ feed, the primes $p$ such that the decimal expansion of $1/p$ repeats with period 2017  are exactly those primes which occur in the prime decomposition of $10^{2017} - 1$ (and for which $10$ isn't equal to $1$ modulo $p$ – this excludes $p = 3$).
The first two prime factors of $10^{2017} - 1$ are $3$ and $129089$. How should I go on to check whether the cofactor, a number with 2012 digits, is prime? It isn't listed on the database maintained by Chris Caldwell when displaying all known primes with 2012 digits, so it's probably not prime.
 A: Let's say $p$ divides $10^{2017}-1$. This means:
$$10^{2017} \equiv 1 \pmod{p}$$
Using group theory, we know that $2017$ must be a multiple of the order of $10 \pmod p$. The order of $10 \pmod p$ is the smallest number $n$ such that $10^n \equiv 1 \pmod p$. We know that $n \neq 1$ because if $10^1 \equiv 1 \pmod p$, then $p=3$ or $p=9$. However,  the only other factor of $2017$ is $2017$, so the order of $10$ must be $2017$.
We also know that the order of $2017$ must divide $\phi(p)$. For a prime $\phi(p)$ is always $p-1$, so this means $2017$ is a divisor of $p-1$, or:
$$p-1 \equiv 0 \pmod{2017}$$
$$p \equiv 1 \pmod{2017}$$
Therefore, other than $3$, any prime factors of $10^{2017}-1$ must be in the form of $2017k+1$. For example, $129089=2017k+1$. Checking for prime factors in the form of $2017k+1$ instead of just all numbers will reduce your search space, but only by a constant factor, so unfortunately, there are still way too many possibilities to check them all even using this strategy.
