• 51nod 1005 1027 1029 高精度


    Java大数用法参考:https://www.cnblogs.com/jin-nuo/p/5313205.html

    1005 大数加法:

    import java.util.*;
    import java.io.*;
    import java.math.*;
    public class Main{
        public static void main(String[] args) {
            Scanner cin=new Scanner(System.in);
            BigInteger a=cin.nextBigInteger();
            BigInteger b=cin.nextBigInteger();
            System.out.println(a.add(b));
        }
    
    }

    1027 大数乘法:

    import java.util.*;
    import java.io.*;
    import java.math.*;
    public class Main{
        public static void main(String[] args) {
            Scanner cin=new Scanner(System.in);
            BigInteger a=cin.nextBigInteger();
            BigInteger b=cin.nextBigInteger();
            System.out.println(a.multiply(b));
        }
    
    }

    1029 大数除法 取模:

    import java.util.*;
    import java.io.*;
    import java.math.*;
    public class Main{
        public static void main(String[] args) {
            Scanner cin=new Scanner(System.in);
            BigInteger a=cin.nextBigInteger();
            BigInteger b=cin.nextBigInteger();
            System.out.println(a.divide(b));
            System.out.println(a.remainder(b));
        }
    
    }

    牛客小白月赛12 B 求A^B mod P

    题目链接:https://ac.nowcoder.com/acm/contest/392/B

    import java.util.*;
    import java.io.*;
    import java.math.*;
     
    public class Main{
        public static void main(String[] args){
            Scanner cin=new Scanner(System.in);
            int T=cin.nextInt();
            while(T>0){
                T--;
                BigInteger a=cin.nextBigInteger();
                BigInteger b=cin.nextBigInteger();
                BigInteger p=cin.nextBigInteger();
                BigInteger res=BigInteger.valueOf(1);
                while(b.compareTo(BigInteger.valueOf(0))!=0){
                    if(b.mod(BigInteger.valueOf(2)).compareTo(BigInteger.valueOf(1))==0)
                        res=res.multiply(a).mod(p);
                    a=a.multiply(a).mod(p);
                    b=b.divide(BigInteger.valueOf(2));
                }
                System.out.println(res);
            }
        }
    }
  • 相关阅读:
    [CF997E] Good SubSegment
    CF916E
    BZOJ2006 超级钢琴
    BZOJ4571
    凸包总结
    树形DP入门
    bzoj4300 绝世好题(位运算+DP)
    bzoj4552 [Tjoi2016&Heoi2016]排序 (线段树+二分)
    SP1716 GSS3
    Noip2009 Hankson 的趣味题 (简单数学)
  • 原文地址:https://www.cnblogs.com/zjl192628928/p/10455623.html
Copyright © 2020-2023  润新知