Ⅰ基本函数:
1.valueOf(parament); 将参数转换为制定的类型
比如 int a=3;
BigInteger b=BigInteger.valueOf(a);
则b=3;
String s=”12345”;
BigInteger c=BigInteger.valueOf(s);
则c=12345;
2.add(); 大整数相加
BigInteger a=new BigInteger(“23”);
BigInteger b=new BigInteger(“34”);
a.add(b);
3.subtract(); 相减
4.multiply(); 相乘
5.divide(); 相除取整
6.remainder();取余
7.pow(); a.pow(b)=a^b
8.gcd(); 最大公约数
9.abs(); 绝对值
10.negate();取反数
11.mod(); a.mod(b)=a%b=a.remainder(b);
12.max(); min();
13.punlic int comareTo();
14.boolean equals(); 是否相等
15.BigInteger构造函数:
一般用到以下两种:
BigInteger(String val);
将指定字符串转换为十进制表示形式;
BigInteger(String val,int radix);
将指定基数的BigInteger的字符串表示形式转换为BigInteger
Ⅱ.基本常量:
A=BigInteger.ONE 1
B=BigInteger.TEN 10
C=BigInteger.ZERO 0
Ⅲ.基本操作
1.读入:
用Scanner类定义对象进行控制台读入,Scanner类在java.util.*包中
Scanner cin=new Scanner(System.in);// 读入
while(cin.hasNext()) //等同于!=EOF
{
int n;
BigInteger m;
n=cin.nextInt(); //读入一个int;
m=cin.BigInteger();//读入一个BigInteger;
System.out.print(m.toString());
}
BigInteger(byte[])
把一个包含着(带正负号)整数的二进制补码的字节数组翻译为 BigInteger 。
BigInteger(int, byte[])
把一个整数的 sign-magnitude 表示法翻译为 BigInteger 。
BigInteger(int, int, Random)
返回有指定 bitLength(可能是素数)的随机选择的 BigInter 。
BigInteger(int, Random)
返回一个随机数,均匀分布在 [0, 2**numBits - 1] 之间
(假设由 rndSrc 提供一个公平的随机源) 。
BigInteger(String)
把一个字符串翻译为一个 BigInteger ,该字符串包含可选的负号,后面跟着一个或多个十进制数字序列。
BigInteger(String, int)
把一个字符串翻译为一个 BigInteger ,该字符串包含可选的负号,后面跟着一个或多个指定进制的数字序列。
| 方法摘要 | |
| abs() | |
| add(BigInteger val) | |
| and(BigInteger val) | |
| andNot(BigInteger val) | |
| int | bitCount() |
| int | bitLength() |
| clearBit(int n) | |
| int | compareTo(BigInteger val) |
| divide(BigInteger val) | |
| divideAndRemainder(BigInteger val) | |
| double | doubleValue() |
| boolean | |
| flipBit(int n) | |
| floatValue() | |
| gcd(BigInteger val) | |
| int | getLowestSetBit() 最右端 1 比特之间的 0 比特的位数)。 |
| int | |
| int | intValue() |
| boolean | isProbablePrime(int certainty) |
| long | longValue() |
| max(BigInteger val) | |
| min(BigInteger val) | |
| mod(BigInteger m) | |
| modInverse(BigInteger m) | |
| modPow(BigInteger exponent, BigInteger m) | |
| multiply(BigInteger val) | |
| negate() | |
| nextProbablePrime() | |
| not() | |
| BigInteger | or(BigInteger val) |
| pow(int exponent) | |
| static BigInteger | probablePrime(int bitLength, Random rnd) |
| remainder(BigInteger val) | |
| setBit(int n) | |
| shiftLeft(int n) | |
| shiftRight(int n) | |
| int | signum() |
| subtract(BigInteger val) | |
| boolean | testBit(int n) |
| byte[] | toByteArray() |
| toString() | |
| toString(int radix) | |
| static BigInteger | valueOf(long val) |
| xor(BigInteger val) | |
本文详细介绍了Java中的BigInteger类,包括基本函数、常量、构造方法及各种数学运算方法。此外还提供了BigInteger类的一些高级用法和实例。
1031

被折叠的 条评论
为什么被折叠?



