码迷,mamicode.com
首页 > 编程语言 > 详细

斯特林公式-Stirling公式(取N阶乘近似值)-HDU1018-Big Number 牛客网NowCoder 2018年全国多校算法寒假训练营练习比赛(第三场)A.不凡的夫夫

时间:2018-02-11 14:32:04      阅读:402      评论:0      收藏:0      [点我收藏+]

标签:one   UI   long   大数   div   describe   str   line   好的   

最近一堆题目要补,一直咸鱼,补了一堆水题都没必要写题解。备忘一下这个公式。

 Stirling公式的意义在于:当n足够大时,n!计算起来十分困难,虽然有很多关于n!的等式,但并不能很好地对阶乘结果进行估计,尤其是n很大之后,误差将会非常大。但利用Stirling公式可以将阶乘转化成幂函数,使得阶乘的结果得以更好的估计。而且n越大,估计得越准确。

传送门:_(:з」∠)_ 

再来一个详细一点的,传送门:( ?′ω`? ) 

 

再来两道题目。

 

HDU1018

Big Number

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


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
 
 
 
代码:
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 const double e=exp(1);
 8 const double pi=acos(-1.0);
 9 int main(){
10     int t;
11     scanf("%d",&t);
12     while(t--){
13         int n;
14         scanf("%d",&n);
15         if(n==1){printf("1\n");continue;}
16         double s=log10(2.0*pi)/2.0+(n+0.5)*log10(n)-n*log10(e);
17         int ans=ceil(s);
18         printf("%d\n",ans);
19     }
20     return 0;
21 }

 

 

 

 

2018年全国多校算法寒假训练营练习比赛(第三场)

A.不凡的夫夫
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

题目描述

夫夫有一天对一个数有多少位数感兴趣,但是他又不想跟凡夫俗子一样,
所以他想知道给一个整数n,求n!的在8进制下的位数是多少位。

输入描述:

第一行是一个整数t(0<t<=1000000)(表示t组数据)
接下来t行,每一行有一个整数n(0<=n<=10000000)

输出描述:

输出n!在8进制下的位数。
示例1

输入

3
4
2
5

输出

2
1
3



代码:
 1 //A-斯特林公式-求位数
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<cmath>
 6 #include<algorithm>
 7 #include<stack>
 8 #include<map>
 9 #include<vector>
10 #include<queue>
11 #include<set>
12 using namespace std;
13 const int inf=1<<30;
14 const int maxn=1e5+10;
15 const double eps=1e-6;
16 const int mod=1e9+7;
17 const double pi=acos(-1.0);
18 const double epx=1e-10;
19 const double e=exp(1);
20 typedef long long ll;
21 int l(int n){
22     int s=1;
23     if(n>3)
24         s=(log(2*pi*n)/log(8))/2+n*(log(n/e)/log(8))+1;
25     return s;
26 }
27 int main(){
28     int n,t;
29     scanf("%d",&t);
30     while(t--){
31         scanf("%d",&n);
32         printf("%d\n",l(n));
33     }
34     return 0;
35 }

 


最近一堆大数的题目写的头都炸了,java学的超级垃圾,c语言版的太长不想写。。。

补题补题,天坑还未补。。。

太垃圾了,我怎么这么菜啊。

 

 

 

斯特林公式-Stirling公式(取N阶乘近似值)-HDU1018-Big Number 牛客网NowCoder 2018年全国多校算法寒假训练营练习比赛(第三场)A.不凡的夫夫

标签:one   UI   long   大数   div   describe   str   line   好的   

原文地址:https://www.cnblogs.com/ZERO-/p/8440970.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!