Problem 542
Self Dividing Numbers in Range
Easy · 10 pts · Math
Problem
A self-dividing number is a positive integer that is divisible by every one of its digits. For example, 128 is self-dividing because 128 is divisible by 1, 2 and 8. A number that contains the digit 0 is never self-dividing, since you cannot divide by zero. Given a range from L to R, print every self-dividing number in it in increasing order, or -1 if there are none.
Input
A single line with two integers L and R.
Output
Print the self-dividing numbers from L to R separated by spaces, or -1 if there are none.
Constraints
1 <= L <= R <= 10000
Example input
1 22
Example output
1 2 3 4 5 6 7 8 9 11 12 15 22
Explanation
From 1 to 22, the numbers 1 to 9 divide themselves, and 11, 12, 15 and 22 are divisible by each of their digits. 10 and 20 contain a 0, so the list is 1 2 3 4 5 6 7 8 9 11 12 15 22.