这道题讲的是求阶乘的位数。

叫自己做真不知道该怎么做。我知道肯定是有公式的。在网上找了下是

斯特林公式:lnN!=NlnN-N+0.5*ln(2*N*pi)

有了这个公式就没问题了

代码:

 

View Code
 1 #include<iostream>
 2 #include<math.h>
 3 #define pi 3.1415926 
 4 using namespace std;
 5 int x,y; 
 6 void putresult()
 7 {
 8     double t=x;
 9     t=(t*log(t)-t+0.5*log(2*t*pi))/log(10.0);
10     y=int(t)+1;
11     cout<<y<<endl; 
12 }
13 int main()
14 {
15     int t;
16     cin>>t;
17     while(t--)
18     {
19         cin>>x;
20         putresult();  
21     } 
22 } 

 

 

 

posted on 2012-09-05 14:24  xinmenghuairi  阅读(229)  评论(0编辑  收藏  举报