- from itertools import permutations as per
- x = lambda l: (l[1]*100+l[2]*10+l[3]) % 2 == 0 and (l[2]*100+l[3]*10+l[4]) % 3 == 0 and (l[3]*100+l[4]*10+l[5]) % 5 == 0 and (l[4]*100+l[5]*10+l[6]) % 7 == 0 and (l[5]*100+l[6]*10+l[7]) % 11 == 0 and (l[6]*100+l[7]*10+l[8]) % 13 == 0 and (l[7]*100+l[8]*10+l[9]) % 17 == 0
- for i in per([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]):
- if i[0] == 0:
- continue
- if x(i):
- print(i)
复制代码
- (1, 4, 0, 6, 3, 5, 7, 2, 8, 9)
- (1, 4, 3, 0, 9, 5, 2, 8, 6, 7)
- (1, 4, 6, 0, 3, 5, 7, 2, 8, 9)
- (4, 1, 0, 6, 3, 5, 7, 2, 8, 9)
- (4, 1, 3, 0, 9, 5, 2, 8, 6, 7)
- (4, 1, 6, 0, 3, 5, 7, 2, 8, 9)
- 请按任意键继续. . .
复制代码 |