Hide

Problem A
Same Digits (Easy)

/problems/samedigitseasy/file/statement/en/img-0001.jpg
Image by Andrey Druc (Shutterstock); Used under license

Two positive integers, $x$ and $y$, are called digit-preserving if their product, $xy$, contains exactly the same digits as $x$ and $y$ contain together, including repetitions. For example, if $x = 807$ and $y = 984$, then their product, $794088$, contains $\textrm{one}~ 7$, $\textrm{one}~ 9$, $\textrm{one}~ 4$, $\textrm{one}~ 0$, and $\textrm{two}~ 8\textrm{'s}$, which is exactly the same set of digits and corresponding frequencies as in $807$ and $984$ combined.

Given an interval, $[A,B]$, find all digit-preserving pairs, $x, y$, in the interval. This means that both $x$ and $y$ are in $[A,B]$, but note that their product, $xy$, is not required to be in $[A,B]$. To avoid double-counting, you can assume $x \leq y$ (this avoids, for example, treating $(807, 984)$ and $(984, 807)$ as different digit-preserving pairs).

Input

The input consists of a single line containing two space-separated integers, $A$ and $B$, with $1 \leq A \leq B \leq 2\, 500$.

Output

First output a single line containing “$n$ digit-preserving pair(s)”, where $n$ is the number of digit-preserving pairs in $[A,B]$. Then output $n$ lines, each of which contains one of the digit-preserving pairs and the corresponding product. Carefully format your output as in the sample output (note the single space separating adjacent tokens). These lines should be sorted by increasing value $\textrm{of}~ x$, breaking ties by increasing value $\textrm{of}~ y$.

Sample Input 1 Sample Output 1
800 1000
12 digit-preserving pair(s)
x = 800, y = 860, xy = 688000
x = 807, y = 984, xy = 794088
x = 825, y = 957, xy = 789525
x = 843, y = 876, xy = 738468
x = 855, y = 927, xy = 792585
x = 858, y = 951, xy = 815958
x = 875, y = 902, xy = 789250
x = 891, y = 909, xy = 809919
x = 891, y = 945, xy = 841995
x = 894, y = 906, xy = 809964
x = 896, y = 926, xy = 829696
x = 953, y = 986, xy = 939658
Sample Input 2 Sample Output 2
987 1234
0 digit-preserving pair(s)

Please log in to submit a solution to this problem

Log in