首页 > 其他分享 >Big Number

Big Number

时间:2023-05-05 20:32:05浏览次数:34  
标签:10 digit log Big number Number integer include


Big Number


Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 26744 Accepted Submission(s): 12173



Problem 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 ≤ n ≤ 107 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




刚看到题目,第一反应便想到大数,但是看看题目,给出的数据可能 达到 10^7 的级别,这么大的数,求阶乘!  oh,my god! 要知道,10000000 的阶乘有六千万多位。

还好,我们有公式, log10(n!)=(0.5*log(2*PI*n)+n*log(n)-n)/log(10) , 这里利用了 log10 (N)=ln(N)/ln(10);

公式的名字是 斯特林公式 维基百科的链接 http://zh.wikipedia.org/wiki/%E6%96%AF%E7%89%B9%E6%9E%97%E5%85%AC%E5%BC%8F


#include <stdio.h>
#include <math.h>
#include<string.h>
#include <stdlib.h>

#define PI 3.14159265
int main()
{
  int n,t,digit;
  scanf("%d",&n);
  while(n--)
  {
    scanf("%d",&t);
    digit=(int)((0.5*log(2*PI*t)+t*log(t)-t)/log(10));
    printf("%d\n",digit+1);                        
  }
  system("pause");
  return 0;    
}


标签:10,digit,log,Big,number,Number,integer,include
From: https://blog.51cto.com/u_16099425/6247727

相关文章

  • (UVA)Big Chocolate
    BigChocolateMohammadhasrecentlyvisited Switzerland .Asheloveshisfriendsverymuch,hedecidedtobuysomechocolateforthem,butasthisfinechocolateisveryexpensive(YouknowMohammadisalittleBITstingy!),hecouldonlyaffordbuyingone......
  • Java中进行高精准度坐标数据计算使用BigDecimal(计算距离、开平方)
    场景Java中使用java.awt.geom.Point2D进行坐标相关的计算(距离、平方等):https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/126072919Java中使用JTS对空间几何计算(读取WKT、距离、点在面内、长度、面积、相交等):https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article......
  • vue学习 第十天(2) HTML5的新特性 ----- 语义化标签(布局标签)/ 多媒体标签(video、
    目标:能够说出3~5个HTML5新增布局和表单标签能够说出CSS3的新增特性有哪些 HTML5的新特性 HTML的新增特性主要是针对于以前的不足,增加了一些新的标签、新的表单和新的表单属性等。新特性都有兼容性问题,基本是IE9+以上版本......
  • JBIG2图像查看器
    JBIG2文件格式是由ISO/IEC14492创建的光栅文件格式。本质上是一种传真机用的图像编码。现在大量使用在PDF中,用于存储二值图,可以获得1:100的压缩率。能够显著减小PDF文件体积。JBIG2格式是用于双色调(黑白)图像的行业标准无损、有损和有损到无损压缩文件格式。与 JBIG、CCITTG3......
  • ImportError: numpy.core.multiarray failed to import (import pyBigWig)
     ---------------------------------------------------------------------------RuntimeErrorTraceback(mostrecentcalllast)RuntimeError:modulecompiledagainstAPIversion0x10butthisversionofnumpyis0xd.Checkthe......
  • linux cpufreq framework(5)_ARM big Little driver
    1.前言也许大家会觉得奇怪:为什么Linuxkernel把对ARMbig·Lttile的支持放到了cpufreq的框架中?众所周知,ARM的big·Little架构,也称作HMP(具体可参考“LinuxCPUcore的电源管理(2)_cputopology”中相关的介绍),通过在一个chip中封装两种不同类型的ARMcore的方式,达到性能和功耗的......
  • 杜教筛 & Powerful Number 筛
    迪利克雷卷积对于数论函数\(F\),\(G\),我们定义迪利克雷卷积的结果\(H=F*G\)为\[H_n=\sum_{d\midn}F_dG_\frac{n}{d}\]有些好的性质,比如:对于积性函数\(F\)与\(G\),其迪利克雷卷积\(F*G\)也是积性函数;而在迪利克雷卷积的意义下,积性函数\(F\)的逆也是积性函数(逆满足\(F......
  • Sololearn website big changes All In One
    SololearnwebsitebigchangesAllInOneLearnPythonoldversionJumptoourbestPythoncourse!Thisoldversionisabouttogoonpermanentvacation.这个旧版本即将永久休假https://www.sololearn.com/learning/1158newversionhttps://www.sololearn.com/l......
  • row_number()over函数的使用(转)
    row_number()over函数的使用(转)      row_number()OVER(PARTITIONBYCOL1ORDERBYCOL2)表示根据COL1分组,在分组内部根据COL2排序,而此函数计算的值就表示每组内部排序后的顺序编号(组内连续的唯一的).与rownum的区别在于:使用rownum进行排序的时候是先对结果集加......
  • Oracle较长number型数值的科学计数显示
    表中有id列,类型为number,在sqlplus中查询的时候,查询结果的显示方式为科学计数法:ID----------4.5572E+184.5574E+184.5585E+18这样看起来很不直观,而之所以这样显示的原因是在SQL*Plus下,小于等于10位的精度显示的是很直观的形式,大于10位精度的则显示为科学计数的形式。避免......