【七月在线OJ】1037 : Sum of Factorials


1037 : Sum of Factorials

include <iostream>

include <fstream>

include <queue>

include <stack>

include <algorithm>

include <string>

include <sstream>

include <climits>

include <cmath>

using namespace std;

define MAX_FACTORIAL_NUM 11

int f[] = {1,1,2,6,24,120,720,5040,40320,362880,3628800};

int main()
{
    int i = 0, n;
    while(cin>>n)
    {
        if(n==0) {cout<<"NO"<<endl; continue;}

        for(i=MAX_FACTORIAL_NUM-1; i>=0&&n!=0; i--)
            if(f[i]<=n) n -= f[i];

        if(n==0) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

    return 0;
}

已邀请:

要回复问题请先登录注册