java大数的基本函数

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类型
divideAndRemainder(BigInteger  val)    返回包含 (this / val) 后跟 (this % val) 的两个 BigInteger 的数组。
boolean isProbablePrime(BigInteger n)  判断大数是否为素数   
modPow(BigInteger n, BigInteger mod)   计算this^n % mod
nextProbablePrime( BigInteger  n )   返回比大数n大的为素数的数
not()   计算  ~this
or( BigInteger a)   计算this|a
xor ( BigInteger  val)     返回其值为 (this ^ val) 的 BigInteger。
probablePrime(int bitLength, Random rnd)    返回有可能是素数的、具有指定长度的正 BigInteger。
shiftLeft(int n)    返回其值为 (this << n) 的 BigInteger。
shiftRight(int n)     返回其值为 (this >> n) 的 BigInteger。
toString(int radix)    返回此 BigInteger 的给定基数的字符串表示形式,默认十进制。
BigInteger p=p.stripTrailingZeros(); //去掉后导0  
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


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值