给你一个数字(例如n!)求这个数字的位数。
1.log(1*2*3*4……)=log(1)+log(2)+log(3)….
#include"cstring"
#include"cstdio"
#include"iostream"
#include"cmath"
using namespace std;
int main()
{
int n,t,i;
double s;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
s=1;
for(i=1;i<=n;i++){
s+=log10(i);
}
printf("%.0lf\n",floor(s));
}
}
2.s=log10(2*PI*n)/2+n*log10(n/E)+1;
#include"cstring"
#include"cstdio"
#include"iostream"
#include"cmath"
using namespace std;
#define PI 3.141592654
#define E 2.71828182846
int main()
{
int n,t,i;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
long long s=1;
if(n>3)
s=log10(2*PI*n)/2+n*log10(n/E)+1;
printf("%lld\n",s);
}
}