Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

hdu 1018

$
0
0

一:log10(n!)=log10(1*2*3…*n)=log10(1)+log10(2)+…+log10(n)

二:n! = sqrt(2*π*n) * ((n/e)^n) * (1 +1/(12*n) + 1/(288*n*n) + O(1/n^3))
π = acos(-1)=3.1415927;
e = exp(1)=2.718281828459;
两边对10取对数
忽略log10(1 + 1/(12*n) +1/(288*n*n) + O(1/n^3)) ≈ log10(1) = 0
得到公式
log10(n!) = log10(sqrt(2 * pi * n)) + n* log10(n / e)。





一:

#include<stdio.h>
#include<math.h>
int main()
{
    int i,n,t;
    double temp=0;
    scanf("%d",&t);
    while(t--)
    {
        temp=0;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
            temp+=log10(i);
        printf("%d\n",(int)temp+1);
    }
    return 0;
}



二:



#include"stdio.h"
#include"math.h"
int main()
{
    int n;
    double temp;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        temp=0.5*log10(2*3.1415927*n)+n*log10(n/2.718281828459);
        printf("%d\n",(int)temp+1);
    }
    return 0;
}






作者:aixiaoling1314 发表于2013-5-24 13:30:15 原文链接
阅读:44 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>