uva 374 Big Mod
赤裸裸的整数快速幂取模
#include <cstdio>
long long PowerMod(long long a, int b, int k)
{
long long tmp = a, ret = 1;
while (b)
{
if (b & 1)
ret = ret * tmp % k;
tmp = tmp * tmp % k;
b >>= 1;
}
return ret;
}
int main()
{
long long a;
int b, k;
while (scanf("%lld %d %d", &a, &b, &k) == 3)
printf("%lld\n", PowerMod(a, b, k));
return 0;
}
posted on 2009-03-15 10:58
sdfond 阅读(1748)
评论(4) 编辑 收藏 引用 所属分类:
Algorithm - Number Theory