Current location - Training Enrollment Network - Mathematics courses - Write a math problem in java language
Write a math problem in java language
//The difficulty of this problem lies in large numbers. Because the order of 1000 is too large, you must use BigInteger.

//That algorithm upstairs is wrong. This problem looks simple, but it is actually more troublesome and difficult than expected.

Import java.math.biginteger;

Import java.util. *;

Win the public class {

Protected static ArrayList table = newArrayList ();

static { table . add(big integer . value of( 1)); }

Public static synchronization BigInteger factorial (int x) (

for(int size = table . size(); Size < = x; size++){

big integer last fact =(big integer)table . get(size- 1);

big integer next fact = last fact . multiply(big integer . value of(size));

table . add(next fact);

}

return(big integer)table . get(x);

}

Public static void main(String[] args){

System.out.print (factorial (1000));

}

}