人见人爱A^B_JAVA_HDU2035

来源:互联网 发布:微信美女诱导支付源码 编辑:程序博客网 时间:2024/06/05 11:03
  • 题目:
    人见人爱A^B :
    http://acm.hdu.edu.cn/showproblem.php?pid=2035

  • 代码 :

    import java.util.Scanner;public class Main {static Scanner sc = new Scanner(System.in);public static void main(String[] args) {    int  a = sc.nextInt();    int b = sc.nextInt();    while(a!=0 || b!=0){        //蒙哥马利幂模运算        int m = 1000;        a%=m;        int r=1;        while(b>0){            if((b&1)== 1)                r=r*a%m;            b>>=1;            a = (a*a)%m;        }        System.out.println(r);        a = sc.nextInt();        b = sc.nextInt();    }}}
  • 其他:

    • 蒙哥马利模幂运算,参见:http://www.cnblogs.com/allensun/archive/2011/01/30/1947808.html
    • 要注意二进制运算在编程中的运用
0 0
原创粉丝点击