problem43.py 383 B

123456789101112131415
  1. #!/usr/bin/env python
  2. from itertools import permutations
  3. def div(d, m):
  4. return not (d[2] + d[1] * 10 + d[0] * 100) % m
  5. s = 0
  6. for d in permutations(range(10)):
  7. if div(d[1:4], 2) and div(d[2:5], 3) and div(d[3:6], 5) \
  8. and div(d[4:7], 7) and div(d[5:8], 11) and div(d[6:9], 13) \
  9. and div(d[7:10], 17):
  10. s += int(''.join(map(str, d)))
  11. print s