1.读入
Scanner cin=new Scanner(System.in);// 读入
while(cin.hasNextInt()) //等同于!=EOF,第一数一定要输入整形的
{
}
大数的一般是:
while(cin.hasNextBigInteger()) //第一个数一定要输入大数的
{
}
while(t-->0) //等同于while(t--)
{
}
2.赋值
BigInteger b=BigInteger.valueOf(a); //a可为int,long,string
3.四则运算
add(); 相加
subtract(); 相减
multiply(); 相乘
divide(); 相除
4.各种函数
pow(); a.pow(b)=a^b
gcd(); 最大公约数
abs(); 绝对值
negate(); 取反数
remainder(); 取余
mod(); a.mod(b)=a%b=a.remainder(b);
max();
min();
punlic int comareTo();
boolean equals(); 是否相等
and(); 例如a.and(b),计算a&b
doubleValue(); 转化为double类型
longValue(); 转化为long类型
floatValue(); 转化为float类型
intValue(); 转化为int类型
not() 计算 ~this
or(BigInteger a) 计算this|a
shiftLeft(int n)
返回其值为 (this << n) 的 BigInteger。
toString(int radix)
返回此 BigInteger 的给定基数的字符串表示形式,默认十进制。
BigInteger p=p.stripTrailingZeros();
String s=p.toPlainString();
if(s.startsWith("0.")) s=s.substring(1);
5.基本常量:
A=BigInteger.ZERO 0
B=BigInteger.ONE 1
C=BigInteger.TEN 10
java大数的基本函数,布布扣,bubuko.com
java大数的基本函数
原文:http://blog.csdn.net/u011466175/article/details/38445723