Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

A prime number not equal to $2$ and $5$ can't have last digit equal to $2,4,5,6$ and $8$.

Is it true that this is the only restriction on last digits of prime numbers? I mean if its true that for any sequence of digits with last digit not equal to $2,4,5,6$ and $8$ there exists a prime number with given sequence of digits?

share|improve this question

5 Answers 5

up vote 15 down vote accepted

I think that you forgot about zero. It's clear that prime number can't have zero as last digit. And if you add zero to your list then your statement is true.

Let $x_1, x_2, \cdots x_n$ be your sequence. Take $x = x_1 10^{n-1} + \cdots + x_n$ --- number formed by this sequence. Then $x$ and $10^n$ are coprime since last digit of $x$ is odd and is not divisible by 5. Hence by Dirichlet theorem there exists infinitely many primes $p$ with $p \equiv x \pmod {10^n}$. Those primes have required last digits.

share|improve this answer
+1: sounds good to me. –  Pete L. Clark Aug 10 '10 at 9:18

Don't forget that the last digit could also be $0$, but there are no such prime numbers (since anything ending in $0$ is divisible by $10$). Otherwise, yes, this is true:

If you have a string of final digits $a_n \cdots a_1$ with $a_1 \neq 0,2,4,5,6,8$, then the number $k = 10^{n-1} a_n + \ldots + a_1$ is not divisible by $2$ or $5$ so is prime to $10^n$. By a celebrated theorem of Dirichlet, the arithmetic progression $k, k + 10^n, k + 2 \cdot 10^n,\ldots$ then contains infinitely many prime numbers. Any one of these is congruent to $k$ modulo $10^n$, which is equivalent to saying that the sequence of the last $n$ digits is $a_n \cdots a_1$.

share|improve this answer
anything ending in zero except zero is divisible by ten… –  Seamus Jan 18 '12 at 15:15
@Seamus: Zero is divisible by $10$: who told you otherwise?!? (For $a,b \in \mathbb{Z}$, one says that $b$ is divisible by $a$ if there exists $c \in \mathbb{Z}$ such that $ac = b$. Try this out with $a = 10$, $b = 0$: it works.) –  Pete L. Clark Jan 18 '12 at 17:52
I was using the faulty heuristic that if $a<b$ then $a$ is not divisible by $b$… –  Seamus Jan 18 '12 at 18:20

Yes, including 0. Generally $\pmod m$ the number of elts coprime to $m$ is counted by the Euler totient function $\phi(m)$. These elts are precisely the units, i.e. invertible elts $\pmod m$. Here $\phi(10) = 4$ with units $\{1,3,7,9\}$ Generally each such unit may be represented by a prime - this is the famous Dirichlet theorem on arithmetic progressions. These units form a group and the study of such unit groups plays a fundamental role in number theory and algebra.

share|improve this answer

When you write down numbers in base $10 = 2\cdot 5$, the last digit only allows to determine divisibility by the base's factors 2 and 5, indicated by $0,2,4,5,6,8$. Would you pick another base, e.g. $30=2\cdot 3\cdot 5$ you could read the divisibility by 3 in addition.

share|improve this answer
+1, interesting point on divisibility. –  Alex Hirzel Jun 7 '11 at 17:53

There is infinite may constrains on digits of the prime number. Each one may be deduced as follows ( from Euclid method): suppose You have number $S = \sum 10^i *a_i$ which is divisible by $p$. Then You have $S= ( \sum 10^j * b_j )*p = \sum 10^j b_j*p $ . You may perform multiplication and look for additional constrains. So as You have criteria for divisibility by 2, 4, or 5, which gives You constraints on last digits, You may construct similar criteria for divisibility by 13 etc. as well. It is possible, that some of them gives You constrains of the form:

for S>p last digit has to be in a set M, where M is proper subset of {1,3,7}

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.