<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ~~~ # Big Number Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 31542????Accepted Submission(s): 14684 ~~~ 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 一開始看見這道題目不是很明白到底是什么意思,搞了好久才明白是:給一個數規定輸入數字的個數,案例中給出了2也就是輸入2個數,輸入的這兩個數求它的階乘的位數,一開始想著是這樣做:直接求指出然后求長度,這是最不需要動腦子的方法,但是,這個方法并不奏效,因為階乘的數值是很大的,普通的int,long類型一旦求比較大的數的階乘的時候往往會溢出,所以最好的方法應該是避免求他的值才行。 斯特林公式就可以用于求這個階乘的位數,斯特林公式(Stirling's approximation)是一條用來取n的階乘的近似值的數學公式。一般來說,當n很大的時候,n階乘的計算量十分大,所以斯特林公式十分好用,而且,即使在n很小的時候,斯特林公式的取值已經十分準確。 上式兩邊同時取log10,得到的是log10(n!) = log10(2*pi*n)/2+n*log10(n/e)所以其位數應該可以表示為: log10(2*pi*n)/2+n*log10(n/e)+1 ~~~ ~~~~ import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); int num = scanner.nextInt(); int[] nums = new int[num]; int num_digit = 0; double d = 1; int i = 0; while(i < num) { num_digit = scanner.nextInt(); if(num_digit >= 2) { d = Math.log10(2 * Math.PI * num_digit) / 2 + num_digit * Math.log10(num_digit / Math.E) + 1; } nums[i] = (int)d; i++; } //System.out.println("====="); for(i = 0 ; i < num; i++) { System.out.println(nums[i]); } } } ~~~ 另外其他的方法還有 位數= log10(1) + log10(2) + log10(3) + ...... + log10(n) 取整數部分后+1
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看