374 - Big Mod
Time limit: 3.000 seconds
Calculate
![]()
for large values of B, P, and M using an efficient algorithm. (That's right, this problem has a time dependency !!!.)
Input
Three integer values (in the order B, P, M) will be read one number per line. B and P are integers in the range 0 to 2147483647 inclusive. M is an integer in the range 1 to 46340 inclusive.
Output
The result of the computation. A single integer.
Sample Input
3 18132 17 17 1765 3 2374859 3029382 36123
Sample Output
13 2 13195
拿来复习下这个函数。。
完整代码:
/*0.012s*/
#include<cstdio>
int main()
{
int b, p, mod, ans;
while (~scanf("%d%d%d", &b, &p, &mod))
{
b %= mod;
ans = 1;
while (p)
{
if (p & 1)
ans = ans * b % mod;
b = b * b % mod;
p >>= 1;
}
printf("%d\n", ans);
}
return 0;
}

本文介绍了一种用于计算大型数值数据的高效算法,特别适用于处理B、P、M等参数的复杂计算任务,强调了算法的时间依赖性。通过实例输入输出展示了算法的应用效果,适合需要快速解决大规模数值计算问题的读者。
653

被折叠的 条评论
为什么被折叠?



