大数 N!——java
发布时间:2020-12-14 02:18:54 所属栏目:大数据 来源:网络整理
导读:? ? n ? 的 阶 乘 Problem Description Given an integer N(0 ≤ N ≤ 10000),your task is to calculate N! ? Input One N in one line,process to the end of file. Output For each N,output N! in one line. Sample Input 1 2 3 Sample Output 1 2 6 ? ?
? ? n ? 的 阶 乘
Problem Description
Given an integer N(0 ≤ N ≤ 10000),your task is to calculate N!
?
Input
One N in one line,process to the end of file.
Output
For each N,output N! in one line.
Sample Input
Sample Output
?
? ?言简意赅,即求n的阶乘。
? ? 附java代码,记之。
? ??
? ??
import java.util.*; import java.math.*; public class Main{ public static void main(String[] args){ Scanner cin=new Scanner(System.in); int a; while(cin.hasNextInt()){ a=cin.nextInt(); BigInteger b=BigInteger.ONE; for(BigInteger i=BigInteger.ONE; i.compareTo(BigInteger.valueOf(a))!=1; i=i.add(BigInteger.ONE)){ b=b.multiply(i); } System.out.println(b); } cin.close(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |