#B4271. Four-Leaf Rose Numbers

    ID: 11928 Type: Default 1000ms 256MiB

Four-Leaf Rose Numbers

Four-Leaf Rose Numbers

A four-leaf rose number is defined as a four-digit number such that the sum of the fourth powers of its digits is equal to the number itself. Formally, a number (x) is a four-leaf rose number if (x = d_1^4 + d_2^4 + d_3^4 + d_4^4), where (d_1, d_2, d_3, d_4) are the digits of (x).

Given two positive integers (N) and (M) ((1 \le N \le M \le 1,000,000)), output all four-leaf rose numbers in the range ([N, M]) in ascending order. Note that by definition the number must be a four-digit number (i.e. between 1000 and 9999).

For example, if (N=1234) and (M=2345), there is one four-leaf rose number: (1634), because (1^4 + 6^4 + 3^4 + 4^4 = 1634).

inputFormat

The input consists of two space-separated positive integers (N) and (M) ((1 \le N \le M \le 1,000,000)).

outputFormat

Output all four-leaf rose numbers in the range ([N, M]) in ascending order, separated by a space. If no such number exists, output an empty line.

sample

1234 2345
1634