南郵OJ 1961コンピュータ基礎知識大会2(new)


コンピュータ基礎知識大会2(new)
時間制限(一般/Java) : 
1000 MS/ 3000 MS          実行メモリ制限:65536 KByte
総提出:167           試験合格:48 
試合の説明
A^Bの最後の三桁の表示の整数(1<=A、B<=100000)を求めます。
入力
A B
出力
A^Bの最後の三桁
サンプル入力
2 3 12 6
サンプル出力
8,984
タイトルソース
コンピュータ基礎知識大会
#include<iostream>

#define MOD 1000

int main(){
	int A,B,weight,result;
	while(scanf("%d%d",&A,&B)==2){
		result = 1;
		weight = A%MOD;
		while(B){
			if(B&1){
				result = result*weight%MOD;
			}
			weight = weight*weight%MOD;
			B >>= 1;
		}
		printf("%d
",result); } }