题解 | #Sum of Factorials#
Sum of Factorials
https://www.nowcoder.com/practice/42cb1c7f7344466b8cb1710cb12d06b1
#include <iostream> using namespace std; int main(){ int n,a[11]; //数组存n! a[0] = 1; for (int i =1; i <= 10; i++){//计算n! a[i] = a[i-1]*i; } while (cin >>n){ if (n == 0) cout <<"NO"<<endl; for (int i = 10; i >= 0; i--){ if (n >= a[i]) n-=a[i]; } if (n == 0) cout<<"YES"<<endl; else cout <<"NO"<<endl; } }