文章
13
粉丝
386
获赞
2
访问
65.0k
预处理找到阶乘,然后遍历即可
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 25;
int arr[N];
int main(){
arr[0] = 1;
for(int i = 1; i < N; i++) arr[i] = arr[i - 1] * i;
int n;
while(scanf("%d", &n) != EOF){
int sum;
for(int i = 0; i < N; i++){
sum = 0;
for(int j = i; j < N && sum < n; j++){
if(sum + arr[j] <= n) sum += arr[j];
}
if(sum == n) break;
}
if(sum == n) printf("YES\n");
else printf("NO\n");
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发