Hex Factorial 高精度

                          Hex Factorial

求n的阶乘结果的十六进制表示中,用多少个0.       java秒之!

 1 import java.io.*;

 2 import java.math.*;

 3 import java.util.*;

 4 

 5 public class Main

 6 {

 7     public static void main(String[] args)

 8     {

 9         Scanner cin=new Scanner(new BufferedInputStream(System.in));

10         int n;

11         BigInteger base=BigInteger.valueOf(16);

12         while(true)

13         {

14             n=cin.nextInt();

15             if(n<0)

16                 break;

17             if(n==0)

18             {

19                 System.out.println("0");

20                 continue;

21             }

22             BigInteger res=BigInteger.ONE;

23             for(int i=2;i<=n;i++)

24                 res=res.multiply(BigInteger.valueOf(i));

25             int ans=0;

26             while(res.equals(BigInteger.ZERO)==false)

27             {

28                 if(res.mod(base).equals(BigInteger.ZERO)==true)

29                     ans++;

30                 res=res.divide(base);

31             }

32             System.out.println(ans);

33         }

34         cin.close();

35     }

36 }

 

你可能感兴趣的:(RIA)