AcWing 3481. 阶乘的和
原题链接
简单
作者:
术
,
2021-05-17 13:15:37
,
所有人可见
,
阅读 202
#include <iostream>
#include <unordered_set>
using namespace std;
int jie(int i)
{
if(i==0||i==1)
return 1;
return jie(i-1)*i;
}
int n;
int a[15];
unordered_set<int> s;
int main()
{
for(int i=0; i<=10; i++)
{
a[i]=jie(i);;
}
for(int i=1;i<1<<11;i++){
int res=0;
for(int j=0;j<11;j++)
if(i>>j&1)
res+=a[j];
//cout<<res<<endl;
s.insert(res);
}
while(cin>>n&&n>=0)
{
if(s.count(n))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
//cout << "Hello world!" << endl;
return 0;
}