您的位置:首页 > 其它

hdu1420 Prepared for New Acmer ——快速幂

2013-06-01 19:33 375 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1420

题目大意:

  中文题。

题目思路:

  赤裸裸的快速幂。呵呵

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;
#define LL long long
LL m;
LL Po(LL a, LL b) {
LL ans = 1;
while (b) {
if (b&1) {
ans = (ans * a) % m;
b--;
}
b /= 2; a = a * a % m;
}
return ans;
}
int main(void) {
LL n, a, b;
#ifndef ONLINE_JUDGE
freopen("1420.in", "r", stdin);
#endif
scanf("%I64d", &n);
while (n--) {
scanf("%I64d%I64d%I64d", &a, &b, &m);
printf("%I64d\n", Po(a, b));
}
return 0;
}


WA了几次……原因就是输入输出要用%I64d,用%lld或者类型不用LL就出错。题目本身是说要范围10^6,如果平方一下,显然就超int了,所以不能用int
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: