码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 3003

时间:2014-08-30 22:54:50      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:blog   os   io   div   log   sp   amp   c   ios   

找规律吧。可以快速幂模

#include <iostream>
#include <cstdio>
using namespace std;

__int64 Power(__int64 a,__int64 b,__int64 k){
	__int64 ans=1;
	a%=k;
	while(b){
		if(b&1){
			ans=ans*a%k;
		}
		b>>=1;
		a=a*a%k;
	}
	return ans;
}

int main(){
	__int64 k;
	while(scanf("%I64d",&k),k){
		__int64 ans=Power(2,k-1,k);
		printf("%I64d\n",(ans+1)%k);
	}
	return 0;
}

  

HDU 3003

标签:blog   os   io   div   log   sp   amp   c   ios   

原文地址:http://www.cnblogs.com/jie-dcai/p/3946900.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!