Problem #41
Difficulty: 5%
Pandigital Prime
Solution Language: Java
Problem Statement
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?
Approach
The solution involves:
- Recognizing that 9-digit and 8-digit pandigitals are divisible by 3 (sum of digits)
- Generating all 7-digit pandigitals in descending order
- Checking each for primality
- Returning the first (largest) prime found