from itertools import combinations
from itertools import permutations
import sympy
def isprime(n):
return sympy.isprime(n)
primes4 = [i for i in range(1001,10000,2) if isprime(i)]
condition2primes = [i for i in range(3,3333,2) if isprime(i)]
prod2oddPrimes = []
for co in combinations(condition2primes,2):
myproduct = co[0]*co[1]
if myproduct > 1000 and myproduct < 10000:
prod2oddPrimes.append(myproduct)
squaresOfPrime = [i**2 for i in range(33,100,2) if isprime(i)]
by2butnotby4s = [i for i in range(1000,10000,2) if i%4==2]
by4butnotby8s = [i for i in range(1000,10000,4) if i%8!=0]
by8butnotby16s = [i for i in range(1000,10000,8) if i%16!=0]
divby16 = [i for i in range(1008,10000,16)]
for comb in combinations('0123456789', 4):
conditions = [0 for i in range(7)]
for perm in permutations(comb):
n = int(''.join(perm))
if n in primes4:
conditions[0] += 1
if n in prod2oddPrimes:
conditions[1] += 1
if n in squaresOfPrime:
conditions[2] += 1
if n in by2butnotby4s:
conditions[3] += 1
if n in by4butnotby8s:
conditions[4] += 1
if n in by8butnotby16s:
conditions[5] += 1
if n in divby16:
conditions[6] += 1
if conditions == [4,7,1,8,2,1,1]:
print(n)