【CodeChef】Small factorials(BigInteger笔记)

You are asked to calculate factorials of some small positive integers.

Input

An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

Output

For each integer n given at input, display a line with the value of n!


题解:题目一定是故意的,用了好多small,其实这道题用java里面的BigInteger类才能够过=。=

在这里积累一下:

  1. 头文件:import java.math.BigInteger;
  2. BigInteger 表示任意大的整数,原则上是,只要你的计算机的内存足够大,可以有无限位的
  3. 常用的值:BigInteger.ONEBigInteger.TENBigInteger.ZERO
  4. 常用的函数:基本的加减乘除,取模,指数,左右移,与或非,异或等都有,用的时候查就试了。列举常见的如下表
    Valueof赋初值,从别的类型转换过来
    add加法
    subtract减法
    multiply乘法
    divide除法
    remainder余数
    pow指数
    gcd公约数
    shiftLeft左移
    xor异或
    intValue转换成int
    equals(CompareTo)判断相等

这道题的代码如下:

 1 import java.io.BufferedReader;
 2 import java.io.IOException;
 3 import java.io.InputStreamReader;
 4 import java.math.BigInteger;
 5 
 6 public class Main {
 7     public static void main(String[] args)throws IOException{
 8         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 9         BigInteger[] fac = new BigInteger[101];
10         fac[0] = fac[1] = BigInteger.ONE;
11         
12         for(int i = 2;i <= 100;i++)
13         {
14             BigInteger temp = BigInteger.valueOf(i);
15             fac[i] = fac[i-1].multiply(temp);
16         }
17         
18         int t = Integer.parseInt(bf.readLine());
19         while(t-- > 0){
20             int num = Integer.parseInt(bf.readLine());
21             System.out.println(fac[num]);
22         }
23     }
24 
25 }

 

转载于:https://www.cnblogs.com/sunshineatnoon/p/3881362.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值