zoukankan      html  css  js  c++  java
  • Big Number

    问题陈述:

      杭州电子科技大学 HANGZHOU DIANZI UNIVERSITY Online Judge Problem - 1018

     

    问题解析:

      公式一:

        n! = 10^m => lg(10^m) = lg(n!) => m = lg(n) + lg(n-1) + lg(n-2) + ... + lg1;

        所以digits = (int)m + 1;

       公式二:stirling公式

        n! ≈ √2PIn(n/e)n                         

        化简:lg(n!) = 1/2lg(2*PI*n) + nlg(n/e);

    代码详解:

    I:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int i, n, t, digits;
    10     double m;
    11     cin >> n;
    12     while(n--) {
    13         m = 0;
    14         cin >> t;
    15         for(i=1; i<=t; i++) {
    16             m += log10(i*1.0);
    17         }
    18         digits = (int)m + 1;
    19         cout << digits << endl;
    20     }
    21     return 0;
    22 }

    II:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int n, t, digits;
    10     double PI = acos(double(-1));
    11     double e = exp(double(1));
    12     cin >> n;
    13     while(n--) {
    14         cin >> t;
    15         digits = (int)(0.5*log10(2*PI*t) + t*log10(t/e)) + 1;
    16         cout << digits << endl;
    17     }
    18     return 0;
    19 }

     转载请注明出处:http://www.cnblogs.com/michaelwong/p/4287232.html

        

  • 相关阅读:
    SSH框架中使用注解和xml配置的区别
    web项目中log4j的配置
    嵌入式—ASCII码
    MATLAB
    MATLAB
    MATLAB
    MATLAB
    CentOS 7将网卡名称eno16777736改为eth0
    图像增强处理
    Debussy与modelsim联仿时 do 文件脚本
  • 原文地址:https://www.cnblogs.com/michaelwong/p/4287232.html
Copyright © 2011-2022 走看看