problems / 269

Self-Dividing Numbers

easy brute-force math 2000 ms · 256 MB

Self-Dividing Numbers

A positive integer is self-dividing if none of its decimal digits is 0 and the number is divisible by every one of its digits.

For example, 128 is self-dividing: 128 % 1 = 0, 128 % 2 = 0 and 128 % 8 = 0. The number 26 is not, because 26 % 6 = 2, and 102 is not, because it contains the digit 0.

Given a range [L, R], count the self-dividing numbers in it and list the smallest of them.

Input

A single line contains two integers L and R (1 ≤ L ≤ R ≤ 10^9, R − L ≤ 10^6).

Output

On the first line, print k, the number of self-dividing numbers x with L ≤ x ≤ R.

On the second line, print the first min(k, 100) of them in increasing order, separated by spaces. If k = 0, the second line is empty.

Notes

In the first example, the self-dividing numbers between 1 and 22 are 1 to 9, 11, 12, 15 and 22. The number 10 contains a zero, and 13, 14, 16, ... fail because they are not divisible by their last digit.

In the second example, every number from 100 to 110 contains a zero except 111, which lies outside the range, so the answer is 0 and the second line is empty.

Both ends of the range are included.

Example 1

Input

1 22

Output

13
1 2 3 4 5 6 7 8 9 11 12 15 22

Example 2

Input

100 110

Output

0

Hints · reveal one at a time if you're stuck

Hint 1

Look at the constraints: the range contains at most about a million numbers. Can you afford to test each one?

Hint 2

Extract the digits of x with x % 10 and x / 10. Reject x as soon as a digit is 0 or does not divide the original x.

report an issue Prefer your own editor? sooks prep 269 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.