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. RDS MySQL 全文检索相关问题的处理

    RDS MySQL 全文检索相关问题 1. RDS MySQL 对全文检索的支持 2. RDS MySQL 全文检索相关参数 3. RDS MySQL 全文检索中文支持 3.1 MyISAM 引擎表 ...

  2. 【SQL 数据库】将一张数据表信息复制到另一张数据表

    一.MySQL数据库 1.如果目标表存在 INSERT INTO 目标表  SELECT  * FROM 源表; 2.如果目标表不存在 CREATE TABLE 目标表 SELECT * FROM   ...

  3. Linux查看可执行程序所在路径

    首先通过命令获得进程PID:如4285,然后执行下述命令 cd /proc/4285 ls -l 或直接ls -l /proc/4285 其中exe所在行即为可执行文件的全路经.如下图所示:

  4. ASP.NET中Url编码解码

    今天遇到Url编码解码的问题,纠结了一天的时间,结果上网一查才发现太二了我们. 同事写的代码把url用HttpUtility.UrlEncode编码和解码了,本地测试没有问题,部署到服务器上就提示转码 ...

  5. Matlab 查看变量信息who whos命令

  6. struts2总结一:MVC设计模式

    设计模式 一.什么是编程里面的设计模式? 1.设计模式是一套被反复使用,多数人知晓的,代码设计经验的总结. 2.模式必须是典型问题(不是个别问题)的解决方案. 二.设计模式的作用 1.解决一类问题的成 ...

  7. Map.Entry用法示例

    一般在HashMap中可以通过key值得到value值,以key作为检索项.Map.Entry<K,V>可以作为条目的检索项.HashMap中有entrySet()方法,返回值是Set&l ...

  8. CodeForceS#276-A

    A. Factory   One industrial factory is reforming working plan. The director suggested to set a mythi ...

  9. 如何清除swap里的文件

    vi打开一个文件的时候突然断网,再次连接上去vi打开的时候提示在swap里面已经存在一个.要删除这个文件怎么办呢? 如下: 关了swapoff -a后 再ls -al查看 把文件所在目录里*.swp结 ...

  10. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 H. Hashing

    H. Hashing time limit per test 1 second memory limit per test 512 megabytes input standard input out ...