A^b
Time Limit: 1000MS |
|
Memory Limit: 65535KB |
|
64bit IO Format: |
Description
Ask for A's B-square, modulo mod (1<=a,b,mod<=1e18)
Input
Multiple sets of inputs, one row per set of data, 3 positive integers, respectively a,b,mod
Output
One row for each set of data output, for the answer
Sample Input
2 10 100000005 100 10 2 37
Sample Output
102400
Template problem, mainly considering the 1e18 of the huge, ordinary fast power will explode ll so in the place of multiplication with the fast multiply, avoid the burst LL.
#include "Cstdio" Long long Mod_mul (long long A,long long B,long long) {Long long r=0;long long t=a; while (b) {if (b&1) R= (r+t)%p;t= (t<<1)%p;b>>=1;} return r;} Long Long Mod_pro (long long A,long long B,long long p) {Long long r=1;long long t=a; while (b) {if (b&1) R=mod_mul (r,t,p )%p;t=mod_mul (t,t,p)%p;b>>=1;} return r;} int main () {Long Long a,b,mod;while (~scanf ("%i64d%i64d%i64d", &a,&b,&mod)) {printf ("%i64d\n", Mod_pro (A, B , MoD));} return 0;}
acm:a^b%p-number theory-fast power-fast multiplication