Kattis - How Many Digits?

How Many Digits?

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 11 kilometer away, and another store is roughly 100100 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-1010.

Input

Input consists of up to 1000010000 integers, one per line. Each is in the range [0,1000000][0,1000000]. Input ends at end of file.

Output

For each integer nn, print the number of digits required to represent n!n! in base-1010.

Sample Input 1Sample 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; 
    }
}

 

转载于:https://www.cnblogs.com/zhien-aa/p/6279646.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值