Problem 74
Armstrong Number
Easy · 10 pts · Math
Problem
A number with k digits is an Armstrong number (also called a narcissistic number) if raising each of its digits to the power k and adding the results gives the number itself. For example, 9474 has 4 digits and 9^4 + 4^4 + 7^4 + 4^4 = 9474. Given N, decide whether it is an Armstrong number. Count the digits first to find k, then add up each digit raised to the power k and compare the total with N. Every one-digit number is an Armstrong number.
Input
A single integer N.
Output
Print YES or NO.
Constraints
1 <= N <= 1000000000
Example input
153
Example output
YES
Explanation
153 has 3 digits, so each digit is cubed: 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153. That equals the number itself, so the answer is YES.