UVA1185 Big Number

2023-05-16

原题:https://www.luogu.com.cn/problem/UVA1185

本题用到的定理的证明:https://www.cnblogs.com/weiliuyby/p/5831991.html

题目:

给出n,求n!的位数

从网上找到了这个公式来求ceil\left( \sum_{i=1}^{x}\log_{10}i \right )答案

注意多组数据哟!!!

AC\ Code:

#include<iostream>
#include<cmath>
using namespace std;
long double ln10[10000001];
int n;
int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		int fact;
		cin >> fact;
		if(fact==1)
		{
			cout << "1" << endl;
			continue;
		}
		long double ans=0.00;
		for(int i=1;i<=fact;i++)
		{
			ans+=log10(i);
		}
		long long answer=ceil(ans);
		cout << answer << endl;
	}
	return 0;
} 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UVA1185 Big Number 的相关文章

  • ROS+Arduino学习导航贴

    前言 原先写了一些ROS 43 arduino学习记录的帖子 xff0c 发现每次找起来非常麻烦 xff0c 所以做一个汇总帖 xff0c 以后需要的话 xff0c 找起来就方便了 关于我用的开发板 xff0c 一开始学习的时候 xff0c

随机推荐