题解 | #Sum of Factorials#
Sum of Factorials
https://www.nowcoder.com/practice/42cb1c7f7344466b8cb1710cb12d06b1
#include<cstdio> int main() { int n; int arr[10]; arr[0] = 1; for (int i = 1 ; i <= 10 ; ++i) { arr[i] = arr[i - 1] * i; } while (scanf("%d", &n) != EOF) { if (n == 0) { printf("NO\n"); } else { for (int i = 10 ; i >= 0; --i) { if (n >= arr[i]) { n -= arr[i]; } } if ( n == 0) { printf("YES\n"); } else { printf("NO\n"); } } } }