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

 

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