Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inline int fastmodpow(int a, int b, int x) {
- a %= x;
- long long pow = 1;
- long long res = 1;
- while (b) {
- if (b & 1) {
- long long pw = a;
- long long i = 1;
- while (i < pow) {
- pw *= pw;
- pw %= x;
- i <<= 1;
- }
- res *= pw;
- res %= x;
- }
- pow <<= 1;
- b >>= 1;
- }
- return int(res % x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement