求1!+2!+3!+…+100!

解决方案 »

  1.   

    import java.math.BigInteger; public class Main 

     public static void main (String[] args) 
     { 
       BigInteger sum = new BigInteger("0");    for (int i = 1; i <= 100; i++) 
       { 
        sum = sum.add(fun(i)); 
       } 
       System.out.println(sum); 
     }  private static BigInteger fun(int times) 
     { 
       BigInteger bi = new BigInteger("1"); 
       for (int i = 2; i <= times; i++) 
       { 
        bi = bi.multiply(new BigInteger(String.valueOf(i))); 
       } 
       return bi; 
     } 

    结果是94269001683709979260859834124473539872070722613982672442938359305624678223479506023400294093599136466986609124347432647622826870038220556442336528920420940313