Fshl0

Overflow Multiplication

Feb 12th, 2021
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ll mul (ll a, ll b, ll m) {
  2.     ll res = 0;
  3.     a %= m;
  4.     while (b > 0) {
  5.         if (b % 2) res = (res + a) % m;
  6.         a = (a * 2) % m;
  7.         b /= 2;
  8.     }
  9.     return res % m;
  10. }
RAW Paste Data