• Java大数运算


    import java.util.*;
    import java.math.*;
    public class Main{
        public static void main(String args[]){
           Scanner cin = new Scanner(System.in);
           BigInteger a, b;
          
           //以文件EOF结束
           while (cin.hasNext()){
               a = cin.nextBigInteger();
               b = cin.nextBigInteger();
              
               System.out.println(a.add(b)); //大整数加法
               System.out.println(a.subtract(b)); //大整数减法
               System.out.println(a.multiply(b)); //大整数乘法
               System.out.println(a.divide(b)); //大整数除法(取整)
               System.out.println(a.remainder(b)); //大整数取模
              
               //大整数的比较
               if( a.compareTo(b) == 0 ) System.out.println("a == b"); //大整数a==b
               else if( a.compareTo(b) > 0 ) System.out.println("a > b"); //大整数a>b
               else if( a.compareTo(b) < 0 ) System.out.println("a < b"); //大整数a<b
              
               //大整数绝对值
               System.out.println(a.abs()); //大整数a的绝对值
              
               //大整数的幂
               int exponent=10;
               System.out.println(a.pow(exponent)); //大整数a的exponent次幂
              
               //返回大整数十进制的字符串表示
               System.out.println(a.toString());
              
               //返回大整数p进制的字符串表示
               int p=8;
               System.out.println(a.toString(p));
           }
        }
    }
  • 相关阅读:
    github登录不上?!
    js -- even-loop 理解
    前端面试积累(整理中)
    各个ctr算法的比较
    常用ctr算法比较
    BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
    Attention is All You Need
    理解word2vec
    EDA时的画图函数
    alphogo 理解
  • 原文地址:https://www.cnblogs.com/zufezzt/p/4794271.html
Copyright © 2020-2023  润新知