大数阶乘
描述我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?
- 输入
- 输入一个整数m(0<m<=5000)
- 输出
- 输出m的阶乘,并在输出结束之后输入一个换行符
- 样例输入
-
50
- 样例输出
-
30414093201713378043612608166064768844377641568960512000000000000
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 public class Main { 5 public static void main(String[] args) { 6 Scanner scanner=new Scanner(System.in); 7 String m; 8 BigInteger i; 9 BigInteger one=new BigInteger("1"); 10 BigInteger mBigInteger; 11 BigInteger jieCheng; 12 13 m=scanner.next(); 14 mBigInteger=new BigInteger(m); 15 16 jieCheng=one; 17 i=one; 18 while(true){ 19 if(i.compareTo(mBigInteger)==1) 20 break; 21 22 jieCheng=jieCheng.multiply(i); 23 i=i.add(one); 24 } 25 System.out.println(jieCheng); 26 } 27 }