杭电oj_2035——人见人爱A^B(java实现)

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2035

思路:(网上学来的,偏向数学的不咋懂/捂脸)每次乘法的时候都取后三位(可能有些含糊,直接看代码吧,一看就懂)

source code:

package hduoj;

import java.util.Scanner;

public class hdoj_2035 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(a==0&&b==0) break;
            if(b==0){
                System.out.println(1);
                continue;
            }
            a %= 1000;
            int r = 1;
            for(int i = 0;i<b;++i){
                r = r*a%1000;
            }
            System.out.println(r);
        }
    }
}

代码已经ac

希望对大家有所帮助

以上

原文地址:https://www.cnblogs.com/lavender-pansy/p/12249240.html