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. filter应用案例三:解决全站编码问题

    1 说明 乱码问题: 获取请求参数中的乱码问题: POST请求:request.setCharacterEncoding("utf-8"): GET请求:new String(re ...

  2. 【MongoDB --番外】错误集合

    1.在第一次安装成功之后,就瞬间发现了如下问题 mongodb无法启动,由于目标计算机积极拒绝,无法连接 解决方法: 这不是mongodb无法启动,是你还没有启动mongodb就来连接使用它了,肯定是 ...

  3. URL编码表%20Base64编码表%20HTTP消息含义

    URL编码表 backspace 8% A 41% a 61% § %A7 Õ %D5   tab 9% B 42% b 62% « %AB Ö %D6   linefeed %0A C 43% c ...

  4. ios透明代理抓包

    之前接到一些ios测试的时候,一些应用往往由于这样那样的原因(比如自实现的发包函数)导致直接使用本地ios系统的代理很难将数据代理到主机的burp或findler中,本文提供了一种解决该问题的途径 原 ...

  5. js Array对象

    http://www.w3cschool.cc/js/js-obj-array.html 创建新方法 原型是JavaScript全局构造函数.它可以构建新Javascript对象的属性和方法. 实例: ...

  6. 《DSP using MATLAB》示例Example4.6

    用到的z变换的性质: 继续解题: 上代码: b = [0,0,0, 0.25, -0.5, 0.0625]; a = [1, -1, 0.75, -0.25, 0.0625]; % polynomia ...

  7. sed 字符串替换

    1. sed替换的基本语法为: sed 's/原字符串/替换字符串/' 单引号里面,s表示替换,三根斜线中间是替换的样式,特殊字符需要使用反斜线”\”进行转义. 2. 单引号” ‘ ’”是没有办法用反 ...

  8. 【oracle】oracle启动和关闭步骤

    前言: 首先要知道,Oracle数据库的完整启动过程是分步骤完成的,包含以下3个步骤: 启动实例-->加载数据库-->打开数据库 因为Oracle数据库启动过程中不同的阶段可以对数据库进行 ...

  9. soapui中文操作手册(八)----Web服务的功能测试案例

    现在,让我们来看看在一个TestCase的功能测试. 展开 Simple TestSuite并双击Simple Login and Logout w. Properties Steps. 正如你所看到 ...

  10. android service 如何弹出dialog

    在service中弹出toast,需要使用handler, handler.post(new Runnable() { @Override public void run() { Toast.make ...