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);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_39564498/article/details/81626544