题解 | #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;
	}
}

全部评论

相关推荐

猪扒已出闸:方向不够聚焦,看不出来是想找什么方向的工作
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务