返回列表 發帖

BigInteger 大數運算

本帖最後由 tonyh 於 2022-1-3 18:52 編輯

  1. import java.math.BigInteger;

  2. public class P6 {

  3.         BigInteger x=new BigInteger("1999999999999999999999999999999999999999999999999");
  4.         BigInteger y=new BigInteger("1000000000000000000000000000000000000000000000001");
  5.         BigInteger i=new BigInteger("2100000000000000000000000000000000000000000000000");
  6.         BigInteger j=new BigInteger("1400000000000000000000000000000000000000000000000");
  7.         long a=1999999999999999999l;
  8.         long b=1000000000000000001l;

  9.         P6()
  10.         {
  11.                 System.out.println(a+b);
  12.                 System.out.println(x.add(y));
  13.                 System.out.println(x.subtract(y));
  14.                 System.out.println(x.multiply(BigInteger.valueOf(2)));
  15.                 System.out.println(x.divide(y));
  16.                 System.out.println(x.remainder(y));
  17.                 System.out.println(i.gcd(j));
  18.                 System.out.println(j.pow(2));
  19.         }

  20.         public static void main(String[] args){
  21.                 new P6();
  22.         }
  23. }
複製代碼

返回列表