版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sdz20172133/article/details/82346645
0012:求10000以内n的阶乘
总时间限制:
5000ms
内存限制:
655360kB
描述
求10000以内n的阶乘。
输入
只有一行输入,整数n(0<=n<=10000)。
输出
一行,即n!的值。
样例输入
100
样例输出
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
来源
java大数总结:点这里
代码实现:点这里
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static BigInteger getTac(BigInteger a)
{
if(a.compareTo(new BigInteger("1")) <= 0)
return new BigInteger("1");
else
return a.multiply(getTac(a.subtract(new BigInteger("1"))));
}
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger m;
while(cin.hasNext())
{
m = cin.nextBigInteger();
m = getTac(m);
System.out.println(m);
}
}
}