基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
 
输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。
 
Input
输入N(1 <= N <= 10^6)
Output
输出N的阶乘的长度
Input示例
6
Output示例
3

果然还是不能暴力做。
这个方法好巧啊,
巧妙的用啦log10函数来求位数。
log10(n!) = log10(1*2*3*...*n)=log10(0)+log10(1)+log10(2)+...+log10(n);

 1 #include <iostream>
 2 #include <cmath>
 3 using namespace std;
 4 int n;
 5 int main(){
 6     cin>>n;
 7     long double ans = 0;
 8     for(int i=1;i<=n;i++){
 9         ans+=log10(i);
10     }
11     long long cnt = ans+1;
12     cout<<cnt<<endl;
13     return 0;
14 }

 

相关文章:

  • 2021-06-17
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
猜你喜欢
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案