一、大数BigInteger
导入:import java.math.*;
方法:
- nextBigInteger() 读入,例如Scanner scan = new Scanner(System.in); BigInteger n = scan.nextBigInteger();
- BigInteger a = new BigInteger(str,radix) 进制转换,把radix进制的字符串str转化为BigInteger
- toByteArray(),toString(),toString(radix进制),intValue(),longValue(),floatValue(),doubleValue() 类型转换
-
compareTo() 比较大小,返回int型,1大于,0等于,-1小于 - max(),min() 返回较大/小的BigInteger型,用法a.max(b)
- BigInteger.ZERO,BigInteger.ONE,BigInteger.TEN 大数常量0,1,10
add() | subtract() | multiply() | divide() | mod() / remainder() | abs() | negate() | pow() | gcd() |
加 | 减 | 乘 | 除 | 取余 | 绝对值 | 相反数 | 幂运算 | 最大公约数 |
and() | or() | xor() | not() | shiftLeft() | shiftRight() | setBit() | testBit() | |
&和 | |或 | ^异或 | ~取反 | <<左移 | >>右移 | 将第n位二进制设为1 | 测试第n位是否为1,返回Boolean型 |
Tip:无特殊说明的都返回BigInteger型。不要忘记都需要赋值!例如:(相应的返回类型) 变量名=大数.方法(XXX);
二、类和二维数组
class Mat{
BigInteger[][] m=new BigInteger[2][2];
}
参考博客:https://blog.youkuaiyun.com/weixin_44259720/article/details/87002816