Often times it is sufficient to know the rough size of a number, rather than its exact value. For example, a human can reason about which store to visit to buy milk if one store is roughly 100 kilometers away. The exact distance to each store is irrelevant to the decision at hand; only the sizes of the numbers matter.

For this problem, determine the ‘size’ of the factorial of an integer. By size, we mean the number of digits required to represent the answer in base-10.

Input

Input consists of up to [0,1000000]. Input ends at end of file.

Output

For each integer 10.

Sample Input 1 Sample Output 1
0
1
3
10
20
1
1
1
7
19

题意

求n的阶乘的长度

思路

公式https://zh.wikipedia.org/wiki/%E6%96%AF%E7%89%B9%E9%9D%88%E5%85%AC%E5%BC%8F

#include<bits/stdc++.h>
using namespace std;
double ans[1000000]={0};
int main(){
    int n;
    for(int i=1;i<=1000000;i++){
            ans[i]+=ans[i-1]+log10(i);
        }
    while(cin>>n){
        cout<<int(ans[n]+1)<<endl; 
    }
}

 

相关文章:

  • 2021-07-06
  • 2021-07-20
  • 2021-05-21
  • 2022-03-06
  • 2022-02-21
  • 2022-01-25
  • 2021-11-30
猜你喜欢
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案