时间限制:3000ms | 内存限制:65535 KB
难度:3
描述
我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?
输入
输入一个整数m(0<m<=5000)
输出
输出m的阶乘,并在输出结束之后输入一个换行符
样例输入
50
样例输出
30414093201713378043612608166064768844377641568960512000000000000
这道题用c写或许比较难,java就是几行代码。暂时没搞懂BigInteger里的setBit方法。。这地方直接用BigInteger的valueOf传入一个值就行。
public class Main {
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
while(scan.hasNext()){
BigInteger bigInteger1=new BigInteger("1");
int a=scan.nextInt();
for(int i=1;i<=a;i++){
bigInteger1=bigInteger1.multiply(BigInteger.valueOf(i));
}
String b=bigInteger1.toString();
System.out.println(b);
}
}
}