首页 > 其他 > 详细

hdu 2035 反复平方法

时间:2015-07-19 18:10:53      阅读:127      评论:0      收藏:0      [点我收藏+]
#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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu 2035 反复平方法

原文:http://blog.csdn.net/qq_24667639/article/details/46955637

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!