1057 N factorial (Java high precision multiplied by single precision)

Factorial of N

Subject link: http://www.51nod.com/Challenge/Problem.html#problemId=1057
Insert picture description here

Problem-solving ideas:

Java large number classes: BigInteger method

code show as below:

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    
    
	public static BigInteger jc(int n) {
    
      //计算阶乘
		BigInteger s = BigInteger.ONE;
		for (int i = 2; i <= n; i++)
			s = s.multiply(new BigInteger(Integer.toString(i)));
		return s;
	}
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		System.out.println(jc(n));
	}
}

Guess you like

Origin blog.csdn.net/weixin_45894701/article/details/114952365