Euler Problem 41
================

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?


```python
from itertools import permutations
from sympy import isprime

for v in permutations(range(7, 0, -1)):
    p = int(''.join(map(str, v)))
    if isprime(p):
        print(p)
        break
```

    7652413


**Explanation:** Every pandigital number $N$ with 8 or 9 digits is divisible by 9, since the sum of the digits of $N$ is $1 + 2 + 3 + \cdots + 8 = 36$ or $1 + 2 + 3 + \cdots + 9 = 45$, respectively. Therefore, pandigital primes have at most 7 digits.

We use `itertools.permutations` to iterate through all permutations of the digits 1-7 in reverse order until we find a permutation that forms a prime number.

13dcc6937807e3d3def082cc840d00e451f35e35
ipynb
Jupyter Notebook
Euler 041 - Pandigital prime.ipynb
Radcliffe/project-euler
5eb0c56e2bd523f3dc5329adb2fbbaf657e7fa38
MIT
2016-05-11T18:55:35.000Z
2019-12-27T21:38:43.000Z
Euler 041 - Pandigital prime.ipynb
Radcliffe/project-euler
5eb0c56e2bd523f3dc5329adb2fbbaf657e7fa38
MIT
Euler 041 - Pandigital prime.ipynb
Radcliffe/project-euler
5eb0c56e2bd523f3dc5329adb2fbbaf657e7fa38
MIT
Qwen/Qwen-72B
1. YES
2. YES