标签:反复平方法
#include <cstdio>
#include <stack>
#include <iostream>
using namespace std;
int fun(int a,int b){
//int c = 0;
int d = 1;
stack<int> st;
while(b){
st.push(b & 1);
b >>= 1l;
}
while(!st.empty()){
int t = st.top();
st.pop();
//c <<= 1;
d = d*d %1000;
if(t == 1){
// c ++;
d = (d*a)%1000;
}
}
return d;
}
int main(){
int a,b;
while(cin >> a >> b,a||b){
cout << fun(a,b) << endl;
}
return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:反复平方法
原文地址:http://blog.csdn.net/qq_24667639/article/details/46955637