编程求x ^y 最后三位数表示的整数。
输入格式:
输入不超过最大整数的两个数x、y
输出格式:
输出x^y最后三位数
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
System.out.println(num(m,n));
}
public static int num(int m,int n){
if (m==0)
return 0;
if (n==0)
return 1;
int result=1;
while (n!=0){
if (n%2==1)
result=(result*m)%1000;
m=(m*m)%1000;
n/=2;
}
return result;
}
}