标签:style blog color java os io 文件 for
You are asked to calculate factorials of some small positive integers.
An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.
For each integer n given at input, display a line with the value of n!
题解:题目一定是故意的,用了好多small,其实这道题用java里面的BigInteger类才能够过=。=
在这里积累一下:
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 }
【CodeChef】Small factorials(BigInteger笔记),布布扣,bubuko.com
【CodeChef】Small factorials(BigInteger笔记)
标签:style blog color java os io 文件 for
原文地址:http://www.cnblogs.com/sunshineatnoon/p/3881362.html