Sunday Times Teaser 3072 – Dial M for Marriage
by Danny Roth
Published Sunday August 08 2021 (link)
George and Martha work in a town where phone numbers have seven digits. “That’s rare!” commented George. “If you look at your work number and mine, both exhibit only four digits of the possible ten (0-9 inclusive), each appearing at least once. Furthermore, the number of possible phone numbers with that property has just four single-digit prime number factors (each raised to a power where necessary) and those four numbers are the ones in our phone numbers.”
“And that is not all!” added Martha. “Both numbers have their highest digits first, working their way down to the lowest, and both give perfect numbers [1] when their digits are summed.”
What are two phone numbers?
[1] A perfect number equals the sum of its factors, eg, 6 = 1 + 2 + 3
or using my number_theory library:
Simple and efficient (allthough not directly tuned to 28).
Here’s a slightly more compact solution