Solution of Subnumbers

Let's analyze some properties of constructing special numbers:

  • We can only use prime digits: 2, 3, 5, 7.
  • We can not use the same digit twice, as it would create a subnumber which is a multiple of 11.
  • If we use 2 or 5, they must be the first digit in the number. Otherwise, at least one subnumber would be either even or a multiple of 5.

All of these constraints reduce the search space by a significant amount. From this point on, we can easily generate all special numbers: [2, 3, 5, 7, 23, 37, 53, 73].

The query constraint is what makes this problem tricky, as there is no special number in the interval [74, 109].

Questions?

Sponsors Gold