hdu——Big Number
发布日期:2022-02-02 02:58:03 浏览次数:1 分类:技术文章

本文共 1046 字,大约阅读时间需要 3 分钟。

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
21020
 

Sample Output
719  


     题目是要求出n!的位数,用到了斯特林数:  

     log10(n!)=1.0/2*log10(2*pi*n)+n*log10(n/e)  

     分析:  

 
      #include #include const double PI=3.14159265;using namespace std;int main(){
int t,n;
double sum;
cin>>t;
while(t--)
{
   cin>>n;
   sum=(n*log(n) - n + 0.5*log(2*n*PI))/log(10)+1;
   cout<<(int)sum<
}
return 0;}

转载地址:https://blog.csdn.net/u010368749/article/details/12715123 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:hdu-寒冰王座(01背包)
下一篇:hdu——1004

发表评论

最新留言

表示我来过!
[***.36.148.179]2022年06月18日 11时40分08秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

最新文章