二、stl ,模拟,贪心等 [Cloned] K - Big Number

原题:

In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number. 

题意:

给出一个大数,要求出这个大数的阶乘的位数。

题解:

显然要直接求阶乘是不太现实的,不过用数组来储存然后计算阶乘应该也不是不可以。但是因为是要求位数,求一个数的位数的公式为Len=(int)log10(M)+1,而阶乘的log运算可以用将乘法转换为加法,所以只要计算从1到n的位数加和然后加一可以求解。

代码:AC

#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	int N;
	cin>>N;
	while(N--)
	{
		long long  n;
		cin>>n;
		int i=1;
		double sum=0;
		for(i=1;i<=n;i++)
		{
			sum+=log10((double)i);
		}
		cout<<(int)sum+1<<endl;
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值