HDU 1042 N!(Java大数求阶乘)
  gSHLoS4ND9Hs 2023年11月02日 27 0


N!


Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 73973    Accepted Submission(s): 21474



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


 



Author

题意:
求n 的阶乘。
思路:
在熟悉下JAVA大数。
直接每一次输入n,循环n次就过了,只不过不能提前打表,跑不出来。。。

import java.util.Scanner;
import java.math.BigInteger;
public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			int n = cin.nextInt();
			BigInteger a = BigInteger.valueOf(1);
			for (int i = 1; i <= n; ++i){
				BigInteger unit = BigInteger.valueOf(i);
				a = a.multiply(unit);
			}
			System.out.println(a.toString());
		}	
	}
}




【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  YgmmQQ65rPv4   2023年11月19日   30   0   0 Java应用程序
  Y8XIq1u6ceQW   2023年11月19日   43   0   0 Java
  AeUHztwqqxTz   2023年11月02日   44   0   0 Javatomcatapache
gSHLoS4ND9Hs
最新推荐 更多