hdu 1018 計算乙個數階乘的位數

2021-06-23 04:45:05 字數 601 閱讀 5636

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

sample input

2

1020

sample output

7

19

題意:求乙個數的階乘的位數

因為根據數學知識可以知道:

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

又因為階乘很可能超出整形,不容易計算,所以就應用log進行計數

#include

#include

int main()

return 0;

}

計算乙個數階乘的位數

給出乙個數n,求出n!的位數。暴力法肯定是不行的,階乘是個增長速度 很快的函式,10!已經有7位了。更直接的方法是log10 n 以10為底n 的對數。因為求位數就是要每次除以10 的,取對數的意義就是10的幾次方才能到n 也就是求了n 有幾位。那麼問題就轉化成求log10 n 了 一種方法是換底公...

統計乙個數的階乘後面0的個數

given an integer n,return the number of trailing zeroes in n note your solution should be in logarithmic time complexity.要求對數時間。首先分析,只有2 5 10才會產生乙個0,n...

求乙個數的階乘中0的個數

連續幾天產出為負,再不寫點東西沒法交代了。public class the number of 0 in factorialn 階乘中有多少0,如果n k 10 m k是乙個不能被10整除的數,那麼m有多少個就有多少個0 n!進行質因數分解n!2 x 3 y 5 z 由於只有2 5 10,所以可以看...