zoukankan      html  css  js  c++  java
  • 【HDU】 1018 Big Number

    大意就是求 :

    log10(n!) = log10(1 * 2 *  3 * .......*n) = log10(1) + log10(2) + ........+log10(n);

    打表的话会MLE,直接递推即可了。后台数据不会非常刁钻。

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int maxn = 10000000;
    //double dp[maxn + 1];
    //void List(){
    //    dp[1] = log10(1.0);
    //    for(int i = 2; i < maxn; i++)
    //        dp[i] = dp[i - 1] + log10(1.0 * i);
    //    return;
    //}
    int main(){
        int T;
        //List();
        scanf("%d",&T);
        while(T--){
            int n;
            scanf("%d",&n);
            double ret = 0;
            for(int i = 1; i <= n; i++)
                ret += log10(1.0 * i);
            printf("%.f
    ",ceil(ret));
        }
        return 0;
    }
    

    另一种方法,就是斯特林公式



    也就是log10(n!) = log(n!) / log(10) = ( n*log(n) - n + 0.5*log(2*π*n))/log(n);

    直接公式就出来了,更快捷。

    这里就不多说了。

  • 相关阅读:
    汇编指令(它不区分大小写)
    汇编
    LINUX命令
    LInux 终端命令
    回文串的Manacher算法
    hdu3336 Counting the string kmp的next数组的应用
    hdu2203kmp匹配
    hdu2087kmp模板练习
    hdu1171kmp果题
    hdu1686kmp果题
  • 原文地址:https://www.cnblogs.com/blfshiye/p/5178229.html
Copyright © 2011-2022 走看看