【JAVA大数训练】N!

N!
Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50539    Accepted Submission(s): 14212

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
JGShining(极光炫影)
 

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
 public static void main(String[] args) {
  Scanner input=new Scanner(System.in);
  while(input.hasNext())
  {
   int n=input.nextInt();
   BigInteger m=BigInteger.ONE;
   for (int i=1;i<=n;i++) {
    m=m.multiply(BigInteger.valueOf((long)i));
   }
            System.out.println(m);
  }
 }
}

//int型数字i转换成BigInteger方法:BigInteger.valueOf((long)i)

时间: 2024-08-02 20:51:04

【JAVA大数训练】N!的相关文章

【JAVA大数训练】大明A+B

大明A+B Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7440    Accepted Submission(s): 2622 Problem Description 话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫"大明". 这时他已经不是那个只会做100以内加法的那个"小明"了

【JAVA大数训练】A + B Problem II

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 196702    Accepted Submission(s): 37626 Problem Description I have a very simple problem for you. Given two integers A and B, yo

【JAVA大数训练】How Many Fibs?

How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3628    Accepted Submission(s): 1457 Problem Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-

【JAVA大数训练】Exponentiation

Exponentiation Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6571    Accepted Submission(s): 1824 Problem Description Problems involving the computation of exact values of very large magnitude

【JAVA大数训练】大菲波数

大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10291    Accepted Submission(s): 3461 Problem Description Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3. 计算第n项Fibonacci数值.   Input 输

java大数乘法的简单实现 浮点数乘法运算_java

复制代码 代码如下: import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.regex.Matcher;import java.util.regex.Pattern; /** * 大数乘法的简单实现, 目前还不是很完善 * Fix:  * 1. 修改前后删除0的一些错误情况 * 2. 支持负数运算 * 3. 判断输入字符串是否符合小数定义

java大数相乘,希望出界抛异常。

问题描述 如题,我自己测试的时候,如果两个int型大数相乘,结果为负,求检测溢出的方法,并掷出异常的代码 解决方案 /** * Multiply two integers, checking for overflow. * * @param x a factor * @param y a factor * @return the product <code>x*y</code> * @throws ArithmeticException if the result can not

介绍Java的大数类(BigDecimal)和八种舍入模式_java

1.BigDecimal简介 BigDecimal 由任意精度的整数非标度值 和32 位的整数标度 (scale) 组成.如果为零或正数,则标度是小数点后的位数.如果为负数,则将该数的非标度值乘以 10 的负scale 次幂.因此,BigDecimal表示的数值是(unscaledValue × 10-scale). 2.BigDecimal的引入 在利用Java编程语言开发银行.金融类等需要对数值进行高精度计算的软件时,我们经常使用BigDecimal和BigInteger这两个大数类,而不是

HDOJ 1042 N!(大数阶乘JAVA)

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 JAVA 大数轻松AC! import java.math.Bi