Fshl0

Hash

Mar 8th, 2020
169
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ll get_hash (string s) {
  2.     ll p = 31, res = 0;
  3.     for (int i = 0; i < s.length(); i++) {
  4.         res += ((s[i] - 'a' + 1) * (p % mod)) % mod;
  5.         res %= mod;
  6.         p *= 31; p %= mod;
  7.     }
  8.     return res;
  9. }
RAW Paste Data