HDU 1018 Big Number

题意:输入一个n,算出n!的位数。

思路:直接套用公式。

        例:123456789=1.23456789*10^8

              log10(123456789)=log10(1.23456789*10^8)=log10(1.23456789)+log10(10^8)=8

             .

             由此可推导n!的位数=log10(n)+1。

 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int n, x;
 8     double y;
 9     cin >> n;
10     while (n--)
11     {
12         y = 0;
13         cin >> x;
14         for (int i = 1; i <= x; i++)
15         {
16             y = y + log10(i*1.0);
17         }
18         cout << (int)y+1 << endl;
19     }
20     return 0;
21 }
原文地址:https://www.cnblogs.com/zyb993963526/p/6326929.html