首页 > 其他分享 >poj 1423 Big Number<<求N!位数>>

poj 1423 Big Number<<求N!位数>>

时间:2022-11-21 20:32:39浏览次数:36  
标签:1423 int Big scanf number poj include log10 LL

Big Number
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 27542 Accepted: 8789
Description

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.
Input

Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 <= m <= 10^7 on each line.
Output

The output contains the number of digits in the factorial of the integers appearing in the input.
Sample Input

2
10
20
Sample Output

7
19
Source

Dhaka 2002


当超时后可以打表出中间几个值,,,打几个值时间复杂度就会缩小几倍。。。。。


代码:

#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int t;scanf("%d",&t);
	while (t--)
	{
		int n;
		int i;
		double j,kai, p=0,s=0;
		scanf("%d",&n);
		int kkk[11]={0,1000000,2000000,3000000,4000000,5000000,6000000,7000000,8000000,9000000};
		double shu[11]={0.0,5565708.917187,11733474.577126,18128483.956099,24671065.737818,31323381.360738,38063144.399049,44875628.728418,51750367.891344,58679536.124036};
		for (i=9;i>=0;i--)
		{
			if (n>=kkk[i])
			{
				s=shu[i];
				p=kkk[i];
				break;
			}
		}
		for (j=p+1;j<n+1;j++)
		{
			s=s+ log10(j);
		}
		long long pp=s;
		printf("%lld\n",pp+1);
	}
	return 0;
}

斯格林公式  代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define PI 3.1415926
#define E 2.7182818
#define LL long long
LL s;
double n;
int main()
{
	int t;scanf("%d",&t);
	while (t--)
	{
		scanf("%lf",&n);
		if (n==1) {
			printf("1\n");
			continue;
		}
		s=(LL)((log10(sqrt(4.0*acos(0.0)*n))+n*(log10(n)-log10(exp(1.0))))+1);
	//	s=(LL)(1+log10(sqrt(2*PI*n)*pow(n/E,(int)n)));
		printf("%lld\n",s);
	}
	return 0;
}


标签:1423,int,Big,scanf,number,poj,include,log10,LL
From: https://blog.51cto.com/u_15886902/5875299

相关文章

  • poj 2506 Tiling 《大数加法+递推》
    TilingTimeLimit:1000MS MemoryLimit:65536K TotalSubmissions:8689 Accepted:4183 DescriptionInhowmanywayscanyoutile......
  • hdoj 1285 2647 4857 poj 2367 2585 《《拓(tuo)扑》》
    其他题目在下面---题目链接:hdoj12852647:很久以前写的了---越想越难这星期要ac  (这里还有一个可爱的故事---嘿嘿)额,先放两个wrong代码,,希望给你们启发,,,第三个ac........
  • CF1695E Ambiguous Dominoes
    CF1695EAmbiguousDominoes如下图,给定\(n\)个\(1\times2\)的多米诺骨牌,每个骨牌两边均写有数字,求一种矩形的构造方案,使得存在\(2\)种不同的方法将多米诺放进矩形......
  • POJ 1573 Robot Motion(BFS)
    RobotMotionDescriptionArobothasbeenprogrammedtofollowtheinstructionsinitspath.Instructionsforthenextdirectiontherobotistomovearelaidd......
  • POJ 1845Sumdiv(数论)
    SumdivTimeLimit:1000MS MemoryLimit:30000KTotalSubmissions:20041 Accepted:5060DescriptionConsidertwonaturalnumbersAandB.LetSbethesumof......
  • Windows VMware虚拟机中安装macOS的Big Sur、Monterey等
    要在VMware虚拟机中安装macOS的BigSur、Monterey、Catalina等,关键是找到可用的unlocker。Unlocker的作用是修改VMware软件,使其支持macOS作为guest系统。以下是我测试成功......
  • 【引用】『转』【大端(Big Endian)与小端(Little Endian)简介】
    【大端(BigEndian)与小端(LittleEndian)简介】ByteEndian是指字节在内存中的组织,所以也称它为ByteOrdering,或ByteOrder。    对于数据中跨越多个字节的对象,我们......
  • BIG T 下学期选修_python作业
    一共提交了10次作业3.1:importrandomb_Set=[]c_Set=[]i=1000while(i):b_Set.append(random.randint(0,10000))i=i-1i=1000while(i):c_Set.append(random.ran......
  • BigDecimal三位分节法
    参考:https://www.cnblogs.com/XT-xutao/p/9882404.htmlpackagecom.woyujiezhen.test;importjava.math.BigDecimal;importjava.text.DecimalFormat;publicclass......
  • Feign 实现 GET 方法传递 POJO
    Feign实现GET方法传递POJO作者:Grey原文地址:博客园:Feign实现GET方法传递POJOCSDN:Feign实现GET方法传递POJO需求SpringMVC支持GET方法直接绑定POJO......