题目地址:http://poj.org/problem?id=1423
计算位数的是 (int) log10(n) + 1
斯特林公式是 n!≈sqrt(2*π*n)*(n/e)^n
联立得:
f(n)=(int){log10[sqrt(2*π*n)]+n*log10(n/e)} + 1;
import java.util.*;
import java.math.*;
import java.text.*;
import java.io.*;public class Main
{public static void main(String[] args) {Scanner cin = new Scanner(new BufferedInputStream(System.in));int T=cin.nextInt();while(T--!=0){int n = cin.nextInt();if(n<=3) System.out.println(1);else {double ans=Math.log10(Math.sqrt(2*Math.PI*n))+n*Math.log10(n/Math.E);System.out.println((int)ans+1);}}}
}