NYOJ 91 阶乘之和

时间:2014-02-13 02:07:34   收藏:0   阅读:329

原题链接

很经典的一道题。

阶乘和有个特点就是前n项和总比第n+1项小,这题就需要这个性质。

附ac代码:

#include <stdio.h>
int a[11];

int jie(int n){ //计算阶乘
	int i, s = 1;
	for(i = 2; i <= n; ++i)
		s *= i;
	return s;
}

int main(){
	int i;
	for(i = 1; i != 11; ++i)
		a[i] = jie(i);
	int t, n;
	scanf("%d", &t);
	while(t-- && scanf("%d", &n)){
		for(i = 9; i; --i)
			if(n >= a[i]) n -= a[i];		
		n == 0 ? printf("Yes\n") : printf("No\n");
	}
	return 0;
}



原文:http://blog.csdn.net/chang_mu/article/details/19118125

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!