java中大数运算Biginteger类的方法调用

来源:互联网 发布:java 时间戳转换成时间 编辑:程序博客网 时间:2024/05/23 01:15

/**

 * 大数运算

 * BigInteger

 * 9192次方

 * 求它除以100的余数

 * 大数运算Biginteger类的方法调用

 */

package com.test1;

import java.math.*;

import java.math.BigInteger;

publicclass test100 {

 

    /**

     * @param args

     */

    static BigIntegerk=BigInteger.valueOf(1);

    static BigIntegerj=BigInteger.valueOf(91);

    static BigIntegern;

    BigDecimal l=new BigDecimal("100");

    static BigIntegerm=new BigInteger("100");

    publicstaticvoid main(String[] args) {

       //TODO Auto-generatedmethod stub

      

//     k=BigInteger.valueOf(1);

//     k=new BigInteger("1");

        for(int i=1;i<=92;i++){

           k=k.multiply(j);

            System.out.println(k.toString());

//         n=k.remainder(m);

            n=k.remainder(m);

            System.out.println(n.toString());

            

        }

 

    }

 

}

//java大数运算Biginteger类的方法调用

//以下代码与本练习没有必要关系,可以删除

class BigIntegerGet

{

    public String getAdd(StringStr1,String Str2){

        String Str3=new String();

        BigInteger BigInt1=new BigInteger(Str1);

        BigInteger BigInt2=new BigInteger(Str2);

        BigInt1=BigInt1.add(BigInt2);//

        Str3=BigInt1.toString();

        return Str3;

    }

    public String getSubtract(StringStr1,String Str2){

        String Str3=new String();

        BigInteger BigInt1=new BigInteger(Str1);

        BigInteger BigInt2=new BigInteger(Str2);

        BigInt1=BigInt1.subtract(BigInt2);//

        Str3=BigInt1.toString();      

        return Str3;

    }

    public String getMultiply(StringStr1,String Str2){

        String Str3=new String();

        BigInteger BigInt1=new BigInteger(Str1);

        BigInteger BigInt2=new BigInteger(Str2);

        BigInt1=BigInt1.multiply(BigInt2);//

        Str3=BigInt1.toString();      

        return Str3;

    }

    public String getDivide(StringStr1,String Str2){

        String Str3=new String();

        BigInteger BigInt1=new BigInteger(Str1);

        BigInteger BigInt2=new BigInteger(Str2);

       BigInt1=BigInt1.divide(BigInt2);//

        Str3=BigInt1.toString();      

        return Str3;

    }

    public String getRemainder(StringStr1,String Str2){//

        String Str3=new String();

        BigInteger BigInt1=new BigInteger(Str1);

        BigInteger BigInt2=new BigInteger(Str2);

        BigInt1=BigInt1.remainder(BigInt2);//余数

        Str3=BigInt1.toString();      

        return Str3;

    }

    public String getGcd(StringStr1,String Str2){

        String Str3=new String();

        BigInteger BigInt1=new BigInteger(Str1);

        BigInteger BigInt2=new BigInteger(Str2);

        BigInt1=BigInt1.gcd(BigInt2);//最大公约数

        Str3=BigInt1.toString();      

        return Str3;

    }

    public String getPow(StringStr1,String Str2){

        String Str3=new String();

        BigInteger BigInt1=new BigInteger(Str1);

        int Int2=Integer.valueOf(Str2);

        BigInt1=BigInt1.pow(Int2);//

        Str3=BigInt1.toString();      

        return Str3;

    }

    public String getMod(StringStr1,String Str2){

        String Str3=new String();

        BigInteger BigInt1=new BigInteger(Str1);

        BigInteger BigInt2=new BigInteger(Str2);

       BigInt1=BigInt1.mod(BigInt2);//

        Str3=BigInt1.toString();       

        return Str3;

    }

    public String getModInverse(StringStr1,String Str2){

        String Str3=new String();

        BigInteger BigInt1=new BigInteger(Str1);

        BigInteger BigInt2=new BigInteger(Str2);

        BigInt1=BigInt1.modInverse(BigInt2);//倒数取模

        Str3=BigInt1.toString();       

        return Str3;

    }

    public String getMax(StringStr1,String Str2){

        String Str3=new String();

       BigInteger BigInt1=new BigInteger(Str1);

        BigInteger BigInt2=new BigInteger(Str2);

        BigInt1=BigInt1.max(BigInt2);//返回较大一个数的值

        Str3=BigInt1.toString();       

        return Str3;

    }

    public String getMin(StringStr1,String Str2){

        String Str3=new String();

        BigInteger BigInt1=new BigInteger(Str1);

        BigInteger BigInt2=new BigInteger(Str2);

        BigInt1=BigInt1.min(BigInt2);//返回较小一个数的值

        Str3=BigInt1.toString();       

        return Str3;

    }

    publicint getHashcode(String Str){

        int hash=-1;

        BigInteger BigInt=new BigInteger(Str);

        hash=BigInt.hashCode();

        return hash;

    }

publicboolean getIsProbablePrime(String Str,int certainty){

        boolean flag=false;

        BigInteger BigInt=new BigInteger(Str);

        flag=BigInt.isProbablePrime(certainty);//素数

        return flag;

    }

}

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 上下楼膝关节疼膝盖疼怎么办 跑步后关节疼该怎么办 后滚翻翻不过去怎么办 走太多路小腿疼怎么办 踢毽子以后期盖右腿内彻疼怎么办 大学体育选修课挂了怎么办 当天贴的砖踩了怎么办 刚贴的瓷砖踩了怎么办 长胶底板太轻怎么办 乒乓球拍胶皮不粘了怎么办 乒乓球拍子胶片太滑怎么办 新买的包黏黏的怎么办 卫星锅收不到台怎么办 养殖厂被卫星拍住怎么办 中六卫星无信号怎么办 晒出成片的斑怎么办 太阳晒出胳膊上长斑怎么办 宇航员在太空死后怎么办 太阳暴晒起的斑怎么办 太阳晒出来的斑怎么办 被认定D级危房怎么办 突然发现两个关系遥远怎么办 如果没有地球人类会怎么办 小锅盖被屏蔽了怎么办 美的冰箱故障通讯不合格怎么办 美的冰箱通讯不合格怎么办 文明6金币降到0怎么办 紫癜肾炎长期尿潜血怎么办 肾移植后血压高怎么办 尿道长了个肿瘤怎么办 吃了有病的鹅怎么办 狗狗得了乳腺瘤怎么办 孕28周还是臀位怎么办 怀孕五个月胎位不正怎么办 33周了胎位不正怎么办 足月胎儿不足5斤怎么办 绒癌观察期怀孕怎么办 宝宝囱门闭合晚怎么办 慢性硬脑膜下血肿复发怎么办 佝偻病导致囟门晚闭怎么办 儿童液体补多了怎么办