Deep beneath an old observatory, engineers labeled every sealed vault door with a numeric code. A code is called resonant if none of its digits is zero and the code itself is evenly divisible by every one of its own digits. For example, 128 is resonant because 128 is divisible by 1, 2, and 8, while 23 is not resonant because 23 is not evenly divisible by 2, and 105 is not resonant because it contains a zero digit.
You are given two integers low and high describing an inclusive range of vault codes installed on the doors of a wing under inspection. Report every resonant code within that range, in increasing order, so the inspection team knows which doors will unlock correctly.
A single line containing two integers low and high.
Print all resonant codes in the range [low, high], inclusive, in increasing order, separated by single spaces on one line. If no resonant code exists in the range, print an empty line.
Example 1
Input
1 22
Expected
1 2 3 4 5 6 7 8 9 11 12 15 22
Explanation
Every integer from 1 to 22 is checked: the single digits 1-9 are always resonant (a number is trivially divisible by its own lone digit); 10 fails because it contains a zero digit; 11 is resonant (11/1=11 twice); 12 is resonant (12/1=12, 12/2=6); 13, 14, 16-21 each fail on at least one digit; 15 works (15/1=15, 15/5=3); 22 works (22/2=11 twice). The resonant codes are 1 2 3 4 5 6 7 8 9 11 12 15 22.
Example 2
Input
47 85
Expected
48 55 66 77
Explanation
Scanning 47 through 85, 48 is resonant (48/4=12, 48/8=6), 55 is resonant (55/5=11), 66 is resonant (66/6=11), and 77 is resonant (77/7=11). Every other number in the range fails to be evenly divisible by at least one of its nonzero digits or contains a zero digit, so the answer is 48 55 66 77.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →