题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=526
//C++代码
//log10(n!)=log10(1)+log10(2)+...+log10(n)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int t,n,i;
cin>>t;
while(t--){
cin>>n;
double sum=0;
for(i=2;i<=n;i++) sum+=log10(i);
cout<<(int)sum+1<<endl;
}
return 0;
}
本文提供了一种解决ZJU ACM 526题的有效方法,通过计算n!的对数来避免整数溢出问题,使用C++实现并详细展示了代码逻辑。
891

被折叠的 条评论
为什么被折叠?



