UVa 374 - Big Mod

时间:2023-03-09 12:47:18
UVa 374 - Big Mod

  题目大意:计算R = BP mod M,根据模运算的性质计算。

  正常计算会超时,可以用分治的思想降低时间复杂度。不过如果遇到00,结果...话说00的结果是1吗?忘了都...

 #include <cstdio>

 int powMod(int base, int exp, int mod)
{
if (exp == ) return ;
int res = powMod(base, exp>>, mod);
res = (res * res) % mod;
if (exp & 0x1 == ) res = (res * base) % mod;
return res;
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int b, p, m;
while (scanf("%d%d%d", &b, &p, &m) != EOF)
{
int res = powMod(b%m, p, m);
printf("%d\n", res);
}
return ;
}