## We shall say that an $n$-digit number is pandigital if it makes use of all the digits $1$ to $n$ exactly once. For example, $2143$ is a $4$-digit pandigital and is also prime.

What is the largest $n$-digit pandigital prime that exists?

### Finding the largest n-digit pandigital prime can be computed by either manual checking or using a computer program. Manually, this is quite laborious, but we can use some basic rules of divisibility to limit our search:

1. Rule of three: the sum of the digits of a number defines its divisibility by 3. For example, a number is divisible by 3 if the sum of its digits is multiples of 3.

2. Any number ending in 0, 2, 4, 5, 6, or 8 is not prime.

We know that a pandigital number of 9 digits (containing the numbers 1 through 9) has the digits summing up to 45 (= 1+2+3+4+5+6+7+8+9), which is a multiple of 3 and therefore is not prime.

Similarly, an 8-digit pandigital number (containing the numbers 1 through 8) has the digits summing up to 36 (=1+2+3+4+5+6+7+8), which is also a multiple of 3 and therefore cannot be prime either.

The largest pandigital number that the sum of the digits is not a multiple of 3 is a 7-digit pandigital number (containing the numbers 1 through 7).

Reducing the search, manually, to only 7-digit pandigital numbers should make it feasible, but it’s still some work. To speed things up, one can skip numbers ending in 2, 4, 5 or 6, as they are not prime.

The largest 7-digit pandigital prime number is 7652413.

For those who know Python programming, here’s a simple program to find the largest pandigital prime:

“`python

from itertools import permutations

from sympy import isprime

def pandigital_primes(n):

digits = “”.join(str(i) for i in range(n, 0, -1))

for perm in permutations(digits):

num = int(“”.join(perm))

if isprime(num):

return num

# Test with 7

print(pandigital_primes(7)) # Output: 7652413

“`

In this Python program, the `pandigital_primes` function generates pandigital numbers of given length `n` in decreasing order and returns the first prime number detected, that is, the largest. The function `isprime` from the sympy library tests a number if it is prime. The test example is for length 7 and the output is 7652413, the largest 7-digit pandigital prime.

##### More Answers:

Pandigital MultiplesInteger Right Triangles

Champernowne’s Constant