Problem 341
Strong Number
Easy · 10 pts · Math
Problem
A strong number is a number that equals the sum of the factorials of its digits. For example, 145 is strong because 1! + 4! + 5! = 1 + 24 + 120 = 145. Remember that 0! = 1. Given N, decide whether it is a strong number. Precomputing the factorials of the digits 0 to 9 makes each check fast.
Input
A single integer N.
Output
Print YES if N is a strong number, otherwise NO.
Constraints
1 <= N <= 1000000000
Example input
145
Example output
YES
Explanation
The digits of 145 give 1! + 4! + 5! = 1 + 24 + 120 = 145, which is the number itself, so the answer is YES.