# Largest prime number with all digits different

What is the largest prime with distinct digits? (It is certainly less than ten digits long.Can you explain it why?

• How many digits are there total? How many of them can I pick before I must get a repeat? Oct 25 '14 at 13:44
• The answer to this question in various bases is given in oeis.org/A132129. Oct 26 '14 at 5:53
• @EricM.Schmidt That link spoils my answer! Suggestion to other readers: try working some out for yourself before clicking on the link. The list goes up to base 10 with values up to base 16 in the comments. Also, try working out the base n representation of each number as the primes in the list are all given in base 10. Oct 26 '14 at 6:58

The answer should be $$p=987654103.$$ As any number using all ten digits would by a multiple of $3$, we are left with only few nine-digit candidates $987654xyz$ that can be checked manually.

• How do you know it has to be of the form $987654xyz$? Oct 26 '14 at 19:35
• Around the 987654000 mark, about one in $ln(10^9) \approx 20$ numbers is prime according to the Prime Number Theorem. So it's a fair guess that the 24 eligible numbers of those form contain a prime. If (by chance) that didn't happen, the next step be would to check numbers of the form $987653xyz$. Oct 26 '14 at 19:47
• @yatima2975 I didn't formulat eit clear enough, but I did test all permutations and this is the largest prime. Note that $\{x,y,z\}$ must be $\{0,1,3\}$ or $\{0,2,3\}$ to avoid divisibility by $3$, and the last digit must be odd. Hence only $\ldots301$ and $\ldots 203$ need to be tested really (and they are composite). - So with the $p$ as in my answer given, the proof that it is correct requires only three primality tests. Oct 26 '14 at 21:27
• The largest number with 10 unique digits is 9876543210, but it's even so divisible by 2 and not a prime. The next few to try might be 9876543201 or 9876543021 or perhaps 9876542301. But, as you say, those are divisible by 3 and so, not primes. It's surprising (and totally not obvious to me) to hear that "any number using all ten digits would by a multiple of 3"... Why is that so? Maybe this should be asked as a seperate question on its own, but you state it so matter-of-factly here in your answer, perhaps you could explain that a bit. Oct 26 '14 at 23:20
• @KevinFegan if the sum of the digits of a number is divisible by 3, the number is divisible by three. Oct 26 '14 at 23:27

Hint: Suppose you had all ten digits - what would the sum of the digits be?

This question depends on the number base being used. It is assumed that the OP meant base 10, but there is nothing special about that (or the answer) except that humans generally have ten fingers. Here are a few others in different bases:

• base 2: 10 (2)
• base 3: 201 (19)
• base 4: 103 (19, using all three non-zero digits always results in a number divisible by 3)
• base 5: 4302 (577, using all four non-zero digits always results in a number divisible by 2)

Higher bases are left as an excerise for the reader!

• If we allow this approach, then I suppose there is no "largest prime with distinct digits", because any prime p can be represented as just a single digit in base p + 1 . . . Oct 26 '14 at 3:28
• base 48112959837082048696: 10 ;P Oct 26 '14 at 22:36
• @x-x Nice try but it's not the largest! It's not even prime! Oct 27 '14 at 1:28
• @numberknot Some interesting insights can be had by playing with this idea, and it can really pull you out of the mode of thinking about numbers as series of glyphs.
– zxq9
Oct 27 '14 at 3:41

If all the digits are used, it will be divisible by 3, right? Same also if you will use the digits 1-9. Therefore, the largest prime number with different digits is less than 10 digits. If it would be nine digits, O is included as one of the digits.