Topic Connection: http://acm.fzu.edu.cn/problem.php?pid=1752
Problem-solving ideas: To use fast power, but not pure use, if the simple use of the words will explode, to multiply the multiplication into addition, and then use and try to use the bit operation ...
On the code:
#include <iostream>#include <cstdio>using namespace STD;typedef Long LongLL; ll multi (ll A, ll B, ll c) {ll ans=0; a=a%c; while(b) {if(b&1) {ans+=a;//ans= (ans+a)%c; if(ans>=c) Ans-=c; } a<<=1;//a= (a+a)%c; if(a>=c) A-=c; b>>=1; }returnAns;} ll Quick (ll A, ll B, ll c) {ll ans=1; while(b) {if(b&1) Ans=multi (ans, A, c); A=multi (A, A, c); b>>=1; }returnAns;}intMain () {LL n,m,mod; while(~scanf("%i64d%i64d%i64d", &n,&m,&mod)) {printf("%i64d\n", Quick (n, M, MoD)); }return 0;}//100000000000000000
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Fzu 1752 a^b%c