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. POJ 2114 Boatherds 树分治

    Boatherds     Description Boatherds Inc. is a sailing company operating in the country of Trabantust ...

  2. ubuntu12.04 安装eclipse

    1:去官网下载最新版的eclipse for linux; 2:cd  /usr/local 用命令 sudo mkdir eclipse 建立一个Eclipse的目录 3:将下载的文件copy到ec ...

  3. nginx配置文件nginx.conf

    #定义Nginx运行的用户和用户组user www www; #nginx进程数,建议设置为等于CPU总核心数.worker_processes 8; #全局错误日志定义类型,[ debug | in ...

  4. 移动Web开发规范

    1.字体设置 使用无衬线字体 body { font-family: "Helvetica Neue", Helvetica, STHeiTi, sans-serif; } 2.设 ...

  5. 分数try catch

    要求:编写一个程序,此程序在运行时要求用户输入一个 整数,代表某门课的考试成绩,程序接着给出“不及格”.“及格”.“中”.“良”.“优”的结论.要求程序必须具备足够的健壮性,不管用户输入什 么样的内容 ...

  6. 浏览器-02 Chromium的多线程

    Chromium 的多线程机制 概述 每个进程都有很多的线程; 多线程主要是为了保证UI线程(chrome 线程,主线程)不会被任何其它费时的操作阻碍而影响对用户的响应; 为了解决多线程通信和同步问题 ...

  7. 03 Javascript初识

    Javascript语言(★★★★★)      Javascript是基于对象和事件驱动的脚本语言,作用在客户端.              特点: * 交互性 * 安全性(不能访问本地的硬盘)   ...

  8. DedeCMS提交自定义表单加入验证码功能

    织梦dedecms网站给自定义表单加dede模板自带验证码的方法. 有时候,我们因为需要给dede网站的自定义表单添加验证码,防止恶意填写表单提交. 我们可以用以下的方法来实现: 首先,我们要找到 / ...

  9. ReSharper 配置及用法(二)

    下载工具 一:Reshaper是什么 即便是那些整天攻击 .NET 和 C# 的人,也常常不得不承认 Visual Studio 确实是个够强大的 IDE,除非他认为更少的 IDE 功能和命令行调试才 ...

  10. iOS学习14之OC NSNumber + NSValue

    1.NSNumber 数值类. 作用:实现基本数据类型与OC对象类型的相互转化. 1> NSNumber创建对象 // 初始化方法 NSNumber *num1 = [[NSNumber all ...