374 - Big Mod
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=310
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; }
作者署名:csdn博客 synapse7
查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索integer
, output
, an d
, mod
, sample
, 取模
, The
, problem
, 快速幂取模算法
, inclusion
, 幂函数
, 快速幂取模
js取模
,以便于您获取更多的相关知识。