1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from itertools import combinations, permutations # select non-zero digits for the tens digits of the five numbers for h5 in combinations(range(1, 10), 5): # the sum of the five numbers sm = 9 * sum(h5) + 45 # permute the remaining five digits for the units digits for l5 in permutations(set(range(10)).difference(h5)): # form the five two digit numbers n5 = tuple(10 * x + y for x, y in zip(h5, l5)) # exactly one of which is divisible by 9 if sum(1 for n in n5 if n % 9 == 0) == 1: # three of the five numbers divide this sum exactly if sum(1 for n in n5 if sm % n == 0) == 3: # find the remaining two numbers t = tuple(n for n in n5 if sm % n != 0) print(f"Total: {sum(t)} = {t[0]} + {t[1]}, numbers: {n5}.") |

Runs in 60 milliseconds.

]]>