HDOJ 1042 N!(大数)

来源:互联网 发布:大众软件 9几年 编辑:程序博客网 时间:2024/06/04 01:27

HDACM1042

import java.math.BigInteger;import java.util.Scanner;public class Main{    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        while(sc.hasNext()){            BigInteger N = sc.nextBigInteger();            System.out.println(factorial(N));        }    }    public static BigInteger factorial(BigInteger N){        BigInteger sum = BigInteger.ONE;        BigInteger i = BigInteger.ONE;        while (i.compareTo(N)!=1) {            sum = sum.multiply(i);            i=i.add(BigInteger.ONE);        }        return sum;    }}
原创粉丝点击