zoukankan      html  css  js  c++  java
  • 关于大数的四则运算


      本文是在我的另一个博客中copy过来的,感觉博客园比较适合写代码就迁过来了

      好久都没有写过日志了,前两天去面试,看到面试题中有关于大数操作的问题,所以回来以后就总结了一下,供笔试着还有要参加acm的同学做一些参考。

    先说一下大数相加:
     1 package com.my.lucene;
     2 
     3  
     4 import java.math.BigInteger;
     5 
     6  
     7 public class test {
     8 public static void main(String[] args) {
     9 String a = "15432321321223123231321"; String  b = "2121212121214354343544354354";
    10 BigInteger bg = new BigInteger(a);
    11 BigInteger gBigInteger= bg.add(new BigInteger(b));
    12 System.out.println(gBigInteger);
    13 }
    14 }
    15 大数相减: 
    16 package com.my.lucene;
    17 
    18 
    19 import java.math.BigInteger;
    20 
    21 
    22 public class test {
    23 public static void main(String[] args) {
    24 String a = "15432321321223123231321"; String  b = "2121212121214354343544354354";
    25 BigInteger bg = new BigInteger(a);
    26 BigInteger gBigInteger= bg.subtract(new BigInteger(b));
    27 System.out.println(gBigInteger);
    28 }
    29 }
    View Code
     

    大数相乘:

     1 package com.my.lucene;
     2 
     3 
     4 import java.math.BigInteger;
     5 
     6 
     7 public class test {
     8 public static void main(String[] args) {
     9 String a = "15432321321223123231321"; String  b = "2121212121214354343544354354";
    10 BigInteger bg = new BigInteger(a);
    11 BigInteger gBigInteger= bg.multiply(new BigInteger(b));
    12 System.out.println(gBigInteger);
    13 }
    14 }
    15 大数除法:
    16 package com.my.lucene;
    17 
    18 
    19 import java.math.BigInteger;
    20 
    21 
    22 public class test {
    23 public static void main(String[] args) {
    24 String a = "15432321321223123231321"; String  b = "2121212121214354343544354354";
    25 BigInteger bg = new BigInteger(a);
    26 BigInteger gBigInteger= bg.divide(new BigInteger(b));
    27 System.out.println(gBigInteger);
    28 }
    29 }
    View Code

    大数相减:

     1 package com.my.lucene;
     2 
     3 
     4 import java.math.BigInteger;
     5 
     6 
     7 public class test {
     8 public static void main(String[] args) {
     9 String a = "15432321321223123231321"; String  b = "2121212121214354343544354354";
    10 BigInteger bg = new BigInteger(a);
    11 BigInteger gBigInteger= bg.subtract(new BigInteger(b));
    12 System.out.println(gBigInteger);
    13 }
    14 }
    View Code
  • 相关阅读:
    linux下动态链接库.so文件 静态链接库.a文件创建及使用
    matlab 自动阈值白平衡算法 程序可编译实现
    C++ 迭代器介绍 [转摘]
    C++ Primer 第三章 标准库类型vector+迭代器iterator 运算
    matlab灰度变彩色+白平衡算法实现
    我和奇葩的故事之失联第七天
    C++ Primer 第三章 标准库类型string运算
    OpenCV白平衡算法之灰度世界法(消除RGB受光照影响)
    查看网络情况netstat指令与动态监控top指令
    linux服务
  • 原文地址:https://www.cnblogs.com/wq920/p/3275837.html
Copyright © 2011-2022 走看看