You are given a positive integer n. Your task is to determine whether it is an Armstrong number. A number is an Armstrong number if it equals the sum of each of its digits raised to the power of the total number of digits.
Input: n = 153
Output: Yes
Explanation: The number 153 has three digits, and 1³ + 5³ + 3³ = 153. Therefore, it is an Armstrong number.
Input: n = 123
Output: No
Explanation: The number 123 has three digits, but 1³ + 2³ + 3³ = 36, which is not equal to 123.
Input: n = 9474
Output: Yes
Explanation: The number 9474 has four digits, and 9⁴ + 4⁴ + 7⁴ + 4⁴ = 9474. Therefore, it is an Armstrong number.
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.
153
Yes
123
No