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?
There are two wys to go about this: Pick a n (number of digits), generate all possible pandigital numbers, then check if its prime. This might take a bit of time. This is a runtime of approximately \( O(n!)\) if I'm not mistaken. OR we can generate all the primes and find the largest Pandigital prime. Producing the primes take a short amount of time. So, the latter approach was taken
But first, is there way to check what n to go up to? Well we know if a number has n digits, in order for it to be prime, it must not contain any divisors. So, easy way to check is to find the sum of the digits, which is easy. For example, 8-digit Pandigital has a sum of digit of 36, which is divisible by 3. So it can't ever be prime. 9-digit is the same as well. 7-digit on the otherhand, can have a Pandigital prime. Hence, we check up this digits! We can also restrict our search (list of primes) up to 7654321 since this is the greatest Pandigital 7-digit number.
Answer: 7652413
Runtime: 7.7 seconds