java提交样例:
import java.util.Scanner;//读
import java.math.*;//大数类
import java.text.*;
public class Main{
public static void main(String args[]){
Scanner cin = new Scanner(System.in);
int t;
t = cin.nextInt();//读取int
while(t--){
//doing something
}
/*
while(cin.hasNext()){
//doing something
}
*/
}
}
读取的部分
BigInteger a;
a = cin.nextInteger();
String s;
s = cin.next();
char c = s.charAt(0);
Long l;
l = cin.nextLong();
大数类的初始化:
BigInteger a = a.BigInteger.valueOf(int or string);
// 123 或者 "1235" 都可以
BigInteger a1 = new BigInteger("1")
大数类的函数:
a = a.add(BigInteger.valueOf(1));// a = a + 1;
a = a.subtract(BigInteger.valueOf(1));// a = a - 1;
a = a.multiply(BigInteger.valueOf(2));// a = a*2;
a = a.divide(BigInteger.valueOf(2));// a = a/2;
a = a.pow(23);// a = a^23;
//注意,只有pow的里边填的是int 其他的都得是BigInteger
BigInteger a1 = new BigInteger("1");
BigInteger a2 = new BigInteger("2");
a1.compareTo(a2);//大于返回1 等于0 小于-1
if( a1.equals(BigInteger.ZERO) ){
//BigInteger.ZERO也可以换成BigInteger.valueOf(xxx);
}
BigDecimal
BigDecimal b = BigDecimal.valueOf(double);
b = b.stripTrailingZeros();//去掉末尾无意义的0
String s = b.toPlainString();//不带指数段 消去科学记数法
//s = s.substring(1); //s = "123456" -> s = "23456"
练习题:
大数阶乘:
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=28
棋盘覆盖
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=45
比较大小
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=73
大数加法
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=103
递推求值
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=114
高精度幂
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=155