您的位置:首页 > 其它

HDU 2035 快速幂

2017-07-20 10:42 162 查看
显然是快速幂的一道裸题啦。
没接触过快速幂的同学查一查吧,挺简单的。
这道题默认的mod是1000(因为它只要后3位而已)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
const int maxn=110;
const int inf=0x3f3f3f3f;

int main()
{
int n,k;
while(scanf("%d%d",&n,&k)==2&&(n||k))
{
int ans=1;
while(k)
{
if(k&1) ans=ans*n%1000;
n=n*n%1000;
k>>=1;
}
printf("%d\n",ans);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: