http://ac.jobdu.com/problem.php?cid=1040&pid=56
- 题目描述:
-
求A^B的最后三位数表示的整数。说明:A^B的含义是“A的B次方”
- 输入:
-
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。
- 输出:
-
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。
- 样例输入:
-
2 3 12 6 6789 10000 0 0
- 样例输出:
-
8 984 1
// 题目57:人见人爱 A ^ B.cpp: 主项目文件。 #include "stdafx.h" #include <cstdio> int pow(int a,int n) { if(n==1) return a; int res=1; if(n&0x01) res=a%1000; int tmp=pow(a,n>>1); res=(res*((tmp*tmp)%1000))%1000; return res; } int main(array<System::String ^> ^args) { int a,n; while(scanf("%d%d",&a,&n)==2) { if(a==0&&n==0) break; int res=pow(a,n); printf("%d\n",res); } return 0; }