# Is there a method to determine a prime number containing the first n digits?

For example, the number $10243$ is prime and contains the digits '0,' '1,' '2,' '3,' and '4.' Similarly, the number $20143$ is prime. Is there a method to determine whether a prime number exists that contains the first, say, $8$ digits? Or whether a number exists that contains an arbitrary number of digits in order starting from an arbitrary number (say, $3, 4, 5, 6, 7$)?

• Do you want the prime to contain only those digits, each exactly once, or something more relaxed? – JimmyK4542 Jul 30 '15 at 6:35

Based on your examples, its not clear if the prime number is allowed to contain digits other than those specified, or if each of the digits specified can be used more than once. Assuming the answer to both of those is "no":

The number $10235647$ is prime, and contains each of the digits $0$ through $7$ exactly once.

For any number with the digits $3,4,5,6,7$ arranged in some order, the sum of its digits will be $3+4+5+6+7 = 15$, and so, that number will be divisible by $3$, and thus, will not be prime.

• You claim that 3+4+5+6+7=15, which is false. 3+4+5+6+7=23, which is not divisible by 3. – James Waldby - jwpat7 Jan 9 '18 at 5:26

Let $d_1,d_2,\dots,d_k$ be an arbitrary sequence of $k$ digits, with $d_k$ odd and not equal to $5$. Let $a=10^k$ and let $b$ be the number with decimal expansion $d_1\dots d_k$. By Dirichlet's Theorem, there are infinitely many primes in the arithmetic progression of numbers of the form $an+b$, so there are infinitely many primes whose decimal expansion ends in $d_1\dots d_k$.

Added: We now look at the "opposite" problem. Let $d_1,d_2,\dots,d_k$ be any sequence of digits, with $d_1\ne 0$. Then there are infinitely many primes whose decimal expansion starts with the digits $d_1,d_2,\dots,d_k$, in that order. The proof is in principle simple, but takes a while to write out. It uses the Prime Number Theorem.