这几天做了几道用大数的题,发现java来做大数运算十分方便。对acmer来说是十分实用的

1.valueOf(parament); 将参数转换为制定的类型

比如 int a=3;

BigInteger b=BigInteger.valueOf(a);

则b=3;

String s=”12345”;

BigInteger c=BigInteger.valueOf(s);

则c=12345;

2.add(); 大整数相加

BigInteger a=new BigInteger(“23”);

BigInteger b=new BigInteger(“34”);

a.      add(b);

3.subtract(); 相减

4.multiply(); 相乘

5.divide();    相除取整

6.remainder(); 取余

7.pow();   a.pow(b)=a^b

8.gcd();   最大公约数

9.abs(); 绝对值

10.negate(); 取反数

11.mod(); a.mod(b)=a%b=a.remainder(b);

12.max(); min();

13.punlic int comareTo();

14.boolean equals(); 是否相等

15.BigInteger构造函数:

 import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main { public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner cin=new Scanner (new BufferedInputStream(System.in));
PrintWriter cout=new PrintWriter(System.out);
int t;
t=cin.nextInt();
int eg=1;
while(t>0)
{
BigInteger eight=new BigInteger("8");
BigInteger seven=new BigInteger("7");
BigInteger one=new BigInteger("1");
String inp;
inp=cin.next();
BigInteger n=new BigInteger(inp);
BigInteger ans;
BigInteger ans2;
ans=n.multiply(n).multiply(eight);
ans2=n.multiply(seven);
ans=ans.subtract(ans2);
ans=ans.add(one);
cout.println("Case #"+eg+": "+ans);
++eg;
--t; }
cout.flush();
} }

大数的所有计算都是与大数之间进行的

BIgInteger a,b;

a=a.add(b);

a=a.substract(b);

a=a.multiply(b);

a=a.divied(b);

a=a.gcd(b);

java 大数计算的更多相关文章

  1. java大数模板

    java 大数计算   这几天做了几道用大数的题,发现java来做大数运算十分方便.对acmer来说是十分实用的 1.valueOf(parament); 将参数转换为制定的类型 比如 int a=3 ...

  2. 收藏的一段关于java大数运算的代码

    收藏的一段关于java大数运算的代码: package study_02.number; import java.math.BigDecimal; import java.math.BigIntege ...

  3. 1873 初中的算术(java大数)

    1873 初中的算术 1 秒 131,072 KB 10 分 2 级题   Noder现在上初三了,正在开始复习中考.他每天要计算型如 (a× a× a× ⋯× a) ...

  4. Java 大数、高精度模板

    介绍: java中用于操作大数的类主要有两个,一个是BigInteger,代表大整数类用于对大整数进行操作,另一个是BigDecimal,代表高精度类,用于对比较大或精度比较高的浮点型数据进行操作.因 ...

  5. Java大数——快速矩阵幂

    Java大数——快速矩阵幂 今天做了一道水题,尽管是水题,但是也没做出来.最后问了一下ChenJ大佬,才慢慢的改对,生无可恋了.... 题目描述: 给a,b,c三个数字,求a的b次幂对c取余. 数据范 ...

  6. 【Java】-BigInteger大数类的使用【超强Java大数模板 总结】

    Scanner cin = new Scanner(new BufferedInputStream(System.in)); 这样定义Scanner类的对象读入数据可能会快一些! 参考这个博客继续补充 ...

  7. Java精确计算小数

    Java在计算浮点数的时候,由于二进制无法精确表示0.1的值(就好比十进制无法精确表示1/3一样),所以一般会对小数格式化处理. 但是如果涉及到金钱的项目,一点点误差都不能有,必须使用精确运算的时候, ...

  8. java大数

    java大数还是很好用的! 基本加入: import java.math.BigInteger; import jave.math.BigDecimal; 分别是大数和大浮点数. 首先读入可以用: S ...

  9. JAVA大数运算

    java大数是个好东西,用起来方便,代码短. 代码如下: import java.util.*; import java.math.*; public class Main { public stat ...

随机推荐

  1. ffmpeg-20160527-git-bin

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...

  2. Java for LeetCode 233 Number of Digit One

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

  3. 7.django之自定义分页记录

    只是大概记录下步骤: 1.表结构: class UserProfile(models.Model): ''' 用户表 ''' user = models.OneToOneField(User,verb ...

  4. NIS 报错No such map passwd.byname. Reason: Can't bind to server which serves this domain

    在NIS—client端使用命令:ypcat passwd ,把错如上题, 原因:client端ypbind服务未启动解决方法:当然是启动ypbind了,命令:service ypbind start ...

  5. [javascript]获取系统时间函数

    var oDate=new Date(); //初始化系统时间函数 alert(oDate.getHours()); //获取时 alert(oDate.getMinutes()); //获取分 al ...

  6. [Android Pro] synchronized与static synchronized 的区别

    reference to :  http://www.cnblogs.com/shipengzhi/articles/2223100.html 1.synchronized与static synchr ...

  7. Vector_h

    #ifndef VECTOR_H #define VECTOR_H #include <algorithm> template<typename Object> class V ...

  8. chaper3_exercise_Uva1585_score

    #include<iostream> #include<string> using namespace std; int main(void) { , j = ; string ...

  9. hdu 5585 Numbers

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5585 思路:对于2和5只须看最后一位数,对于三看所有位的数字之和就行 #include<stdi ...

  10. CSS学习笔记----CSS3自定义字体图标

    响应式网页字体图标 作者:大漠 日期:2014-01-28 点击:3220 @font-face Responsive 本文由大漠根据Jason的<Responsive Webfont Icon ...