HDU-1018(水题)

题目信息:http://acm.hdu.edu.cn/showproblem.php?pid=1018

题意:求n阶乘的位数

求n的位数公式:(int)log10(n)+1;

求n阶乘位数就是每个里面相加;

代码如下:

#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int main() {
	int t,n;
	double ans;
	scanf("%d",&t);
	while(t--) {
		scanf("%d",&n);
		ans=0;
		for(int i=1; i<=n; i++)
			ans+=log10(i);
		printf("%d\n",(int)ans+1);
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章