-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path49.py
32 lines (27 loc) · 827 Bytes
/
49.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from itertools import permutations, combinations
def is_prime(n):
if n == 2 or n == 3:
return True
if n < 2:
return False
if n % 2 == 0:
return False
if n%6 != 1 and n%6 != 5:
return False
for k in range(3, round(n**0.5+1), 2):
if n%k == 0:
return False
return True
for m in range(1000, 10000):
if is_prime(m):
sk = str(m)
else:
continue
perms = [int(''.join(k)) for k in set(permutations(sk)) if k[0] != '0' and
k[-1] not in ('0', '2', '4', '6', '8') and
is_prime(int(''.join(k)))]
choose_2 = combinations(perms, 2)
for comb in choose_2:
d = sorted([m, comb[0], comb[1]])
if 2*d[1] == d[0] + d[2]:
print(' '.join(map(str, d)))