Armstrong Numbers in a Range
easyPlacement Coding+10 XPTime limit 2s
A number with k digits is an Armstrong number if the sum of each digit raised to the power k equals the number itself. For example, 153 has 3 digits and 1³ + 5³ + 3³ = 153.
Print every Armstrong number from a to b (both included).
Input: one line with a and b.
Output: the Armstrong numbers in increasing order, separated by spaces — or -1 if there are none.
Constraints: 1 ≤ a ≤ b ≤ 10⁶.
Think about it: count the digits first (k), then add up digit^k for every digit. Every single-digit number is an Armstrong number.
Sample input 1
100 500
Sample output 1
153 370 371 407
Sample input 2
10 100
Sample output 2
-1
Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).