天天看點

數的長度

數的長度

時間限制:3000 ms | 記憶體限制:65535 KB

難度:1

描述

N!階乘是一個非常大的數,大家都知道計算公式是N!=N*(N-1)······*2*1.現在你的任務是計算出N!的位數有多少(十進制)?

輸入

首行輸入n,表示有多少組測試資料(n<10)

随後n行每行輸入一組測試資料 N( 0 < N < 1000000 )

輸出

對于每個數N,輸出N!的(十進制)位數。

樣例輸入

3

1

3

32000

樣例輸出

1

1

130271

public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    while(a>0){
      a--;
      int b=sc.nextInt();
      BigInteger num=new BigInteger( 1+"");
      for(int i=1;i<=b;i++){
        num=num.multiply(new BigInteger(i+""));
      }
      String i=num.toString();
      int y=i.length();
      System.out.println(y);
    }
  }