N is an 11-digit base ten prime number N (with no leading zero) with the proviso that N contains each of the digits from 0 to 9 at least once.
Determine the respective minimum and maximum value of N.
The smallest is 10123457689
The largest is 98876532401
------------
def isprime(n):
'''check if integer n is a prime'''
n = abs(int(n))
if n < 2:
return False
if n == 2:
return True
if not n & 1:
return False
for x in range(3, int(n**0.5)+1, 2):
if n % x == 0:
return False
return True
bigsmall = '98876543210'
smallbig = '01123456789'
from itertools import permutations
for perm in permutations(smallbig):
if perm[0] == '0':
continue
n = (int(''.join(perm)))
if isprime(n):
print('The smallest is',n)
break
for perm in permutations(bigsmall):
n = (int(''.join(perm)))
if isprime(n):
print('The largest is',n)
break
|
Posted by Larry
on 2023-06-12 17:56:22 |