Big Number

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

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
 
Source
 题意:
求N!的位数。
代码:
 /*
1:log10(12345)=log10(1.2345*10^4)=4+log(1.2345);n的位数就是log10(n)+1;可以暴力。
2:斯特林公式:一个数的阶乘近似等于sqrt(2*PI*n)*(n/e)^n;
*/
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
int n,m;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
double ans=;
for(int i=;i<=m;i++)
ans+=log10(i);
printf("%d\n",(int)ans+);
}
return ;
} #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
const double e=2.718281828459;
const double PI=3.14159265;
int main()
{
int n,m;
scanf("%d",&n);
while(n--)
{
double ans;
scanf("%d",&m);
if(m!=)
ans=0.5*log10(*PI*m)+m*log10(m)-m*log10(e)+;
else ans=1.0;
printf("%d\n",(int)ans);
}
return ;
}
//两个大数相加用字符串处理。
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main()
{
int t;
char s1[],s2[];
scanf("%d",&t);
for(int k=;k<=t;k++)
{
scanf("%s%s",s1,s2);
int ks1=strlen(s1);
int ks2=strlen(s2);
ks1--;ks2--;
int sav=,h=,a1,a2;
char s[];
while()
{
if(ks1<&&ks2<)
break;
if(ks1>=&&ks2>=)
{
a1=s1[ks1]-'';
a2=s2[ks2]-'';
}
if(ks1>=&&ks2<)
{
a1=s1[ks1]-'';
a2=;
}
if(ks1<&&ks2>=)
{
a1=;
a2=s2[ks2]-'';
}
ks1--;ks2--;
int tem=a1+a2+sav;
sav=tem/;
tem%=;
s[h++]=tem+'';
}
if(sav!=)
s[h++]=sav+'';
printf("Case %d:\n",k);
printf("%s + %s = ",s1,s2);
for(int i=h-;i>=;i--)
cout<<s[i];
printf("\n");
if(k!=t)
printf("\n");
}
return ;
}

HDU 1018 大数(求N!的位数/相加)的更多相关文章

  1. HDU 1018 Big Number (阶乘位数)

    题意: 给一个数n,返回该数的阶乘结果是一个多少位(十进制位)的整数. 思路: 用对数log来实现. 举个例子 一个三位数n 满足102 <= n < 103: 那么它的位数w 满足 w ...

  2. N的阶乘的长度 V2(斯特林近似) 求 某个大数的阶乘的位数 .

    求某个大数的阶乘的位数 . 得到的值  需要 +1 得到真正的位数 斯特林公式在理论和应用上都具有重要的价值,对于概率论的发展也有着重大的意义.在数学分析中,大多都是利用Г函数.级数和含参变量的积分等 ...

  3. hdu Big Number 求一个数的位数

    Problem Description In many applications very large integers numbers are required. Some of these app ...

  4. HDU 1018 Big Number

    LINK:HDU 1018 题意:求n!的位数~ 由于n!最后得到的数是十进制,故对于一个十进制数,求其位数可以对该数取其10的对数,最后再加1~ 易知:n!=n*(n-1)*(n-2)*...... ...

  5. hdu1018 Big Number 斯特林公式 求N!的位数。

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. 大数求模 sicily 1020

        Search

  7. 如何运用同余定理求余数【hdoj 1212 Big Number【大数求余数】】

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. POJ 2635 The Embarrassed Cryptographer(大数求余)

    题意:给出一个大数,这个大数由两个素数相乘得到,让我们判断是否其中一个素数比L要小,如果两个都小,输出较小的那个. 分析:大数求余的方法:针对题目中的样例,143 11,我们可以这样算,1 % 11 ...

  9. java实现:将一个数各个位数相加

    前面已经实现过这个程序,现在我们就不多说了,直接更改C的源码,实现这个JAVA程序. import java.util.Scanner; public class HelloWorld { publi ...

随机推荐

  1. DOM兼容

    -firstChild  firstElementChild var oFirst = oUl.firstChild || oUl.firstElementChild; -lastChild   la ...

  2. LoadRunner常见函数分析

    LoadRunner常见函数分析 ?%Ze\N%?~"_J}.t051Testing软件测试网;FQ X%L|GO+R Web用户Action51Testing软件测试网b,Q8iO w1j ...

  3. 配置.net连接数据库的配置文件

    今天调试一个学生信息管理系统时,启动系统之后,登录时老是报错说实例有问题,拿着报错信息去找方法也没遇到能解决问题的,最后怀疑是数据库配置和配置文件不匹配, 发现自己的数据库里并没有SQLEXPRESS ...

  4. iOS10 UI教程基改变视图的外观与视图的可见性

    iOS10 UI教程基改变视图的外观与视图的可见性 视图是应用程序的界面,是用户在屏幕上看到的对象.用户可以通过触摸视图上的对象与应用程序进行交互,所以视图界面的优劣会直接影响到了客户体验的好坏.和视 ...

  5. 非传统题【A002】

    [A002]非传统题[难度A]————————————————————————————————————————————————————————————————————————————————————— ...

  6. MFC 打开文件夹 调用其他程序 打开文件

    ShellExecute(NULL,TEXT("OPEN"),要打开的文件的路径,NULL,NULL,SW_SHOWNORMAL); ShellExecute(NULL, &quo ...

  7. Python学习笔记03

      区间访问:[from:to:step] step默认是1:from表示起始索引(包括),to表示结束索引(不包括) step如果有符号,表示方向从右到左; from,to有符号,表示从倒数开始算, ...

  8. Struts2上传大小限制

    Struts中报错 the request was rejected because its size (***) exceeds the configured maximum (2097152) 最 ...

  9. 【Oracle】表空间容量修改

    -- 查看表空间容量 SELECT UPPER(F.TABLESPACE_NAME) "表空间名", D.TOT_GROOTTE_MB "表空间大小(M)", ...

  10. java 程序中添加socks 5代理

    在需要使用代理的地方添加如下code: System.getProperties().put("socksProxySet","true"); System.g ...