ACM HOJ 1018 Big Number
14204 ワード
Big Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10639 Accepted Submission(s): 4780
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 ≤ 10
7 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
Asia 2002, Dhaka (Bengal)
Recommend
JGShining
スターリング式はn次乗近似値をとるための数学式である.一般に,nが大きい場合,n次乗の計算量は非常に大きいので,スターリング式は非常に使いやすく,また,
nが小さい頃,スターリング式の値は非常に正確であった.
式は次のとおりです.
すなわち、この2つの数は、十分な整数nに対して互いに近似値である.より正確に:
または、
#include
#include
using namespace std;
const double PI=acos(-1.0);
const double e=exp(1.0);
int main()
{
int T,n;
cin>>T;
while(T--)
{
cin>>n;
if(n!=1)
cout<<(int)(0.5*log10(2*PI*n)+n*log10(n/e)+1)< else cout<<1< }
return 0;
}
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10639 Accepted Submission(s): 4780
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 ≤ 10
7 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
Asia 2002, Dhaka (Bengal)
Recommend
JGShining
スターリング式はn次乗近似値をとるための数学式である.一般に,nが大きい場合,n次乗の計算量は非常に大きいので,スターリング式は非常に使いやすく,また,
nが小さい頃,スターリング式の値は非常に正確であった.
式は次のとおりです.
すなわち、この2つの数は、十分な整数nに対して互いに近似値である.より正確に:
または、
n!=(2*pi*n)^1/2 *(n/e)^n *e^(a/12*n)
#include
#include
using namespace std;
const double PI=acos(-1.0);
const double e=exp(1.0);
int main()
{
int T,n;
cin>>T;
while(T--)
{
cin>>n;
if(n!=1)
cout<<(int)(0.5*log10(2*PI*n)+n*log10(n/e)+1)<
return 0;
}
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
int n,i;
double sum;
int T;
scanf("%d",&T);
while(T--)
{
sum=1;
scanf("%d",&n);
if(n==1){printf("1
");continue;}
for(i=2;i<=n;i++)
{
sum+=log10((double)i);
}
printf("%d
",(int)sum);
}
return 0;
}
#include<cmath>
#include<stdio.h>
#include<iostream>
using namespace std;
const double PI=acos(-1.0);
const double e=exp(1.0);
int main()
{
int T,n,i;
int cnt;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
if(n==1){printf("1
");continue;}// , ,WR
cnt=(int)(0.5*log10(2*PI*n)+n*log10(n/e)+1);
printf("%d
",cnt);
}
return 0;
}
#include<stdio.h>
#include<cmath>
using namespace std;
const double PI=acos(-1.0);
const double e=exp(1.0);
int main()
{
int n,cnt;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
cnt=(int)(0.5*log10(2*PI*n)+n*log10(n/e))+1;
printf("%d
",cnt);
}
return 0;
}