/**
* TABLE LOOKUP FACTORIAL COMPUTATION
* calculate n factorial.
* Only good for 0 <= n <= 20
* @author Roedy Green
* works by table look up
*/
static long factorial (int n)
{
if ( ! ( 0 <= n && n <= 20 ) )
{
throw new IllegalArgumentException( "factorial can only handle 0 <= n <= 20" );
}
return factorials[ n ];
}
static private long [] factorials =
{
1L ,
1L ,
2L ,
6L ,
24L ,
120L ,
720L ,
5040L ,
40320L ,
362880L ,
3628800L ,
39916800L ,
479001600L ,
6227020800L ,
87178291200L ,
1307674368000L ,
20922789888000L ,
355687428096000L ,
6402373705728000L ,
121645100408832000L ,
2432902008176640000L
}