Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. inline int fastmodpow(int a, int b, int x) {
  2. a %= x;
  3. long long pow = 1;
  4. long long res = 1;
  5. while (b) {
  6. if (b & 1) {
  7. long long pw = a;
  8. long long i = 1;
  9. while (i < pow) {
  10. pw *= pw;
  11. pw %= x;
  12. i <<= 1;
  13. }
  14. res *= pw;
  15. res %= x;
  16. }
  17. pow <<= 1;
  18. b >>= 1;
  19. }
  20. return int(res % x);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement