You are given two integers L and R. Your task is to print all Armstrong numbers in the inclusive range [L, R] in ascending order, separated by spaces. An Armstrong number equals the sum of its digits, each raised to the power of the total number of digits.
Input: L = 1, R = 500
Output: 1 2 3 4 5 6 7 8 9 153 370 371 407
Explanation: These are all the Armstrong numbers in the range from 1 to 500.
Input: L = 100, R = 200
Output: 153
Explanation: The only Armstrong number in this range is 153, because 1³ + 5³ + 3³ = 153.
Input: L = 10, R = 99
Output: (empty)
Explanation: No two-digit numbers are Armstrong numbers, so there are no numbers to print.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
1 10
1 2 3 4 5 6 7 8 9
100 500
153 370 371 407