Advertisement
anechka_ne_plach

Untitled

Nov 6th, 2021
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #pragma once
  2. #include <cstring>
  3.  
  4. constexpr int hash(const char *s, int p, int mod) {
  5.     return std::strlen(s) == 0 ? 1 : std::strlen(s) == 1 ? s[0] : (p * hash(s + 1, p, mod) % mod);
  6. }
  7.  
  8. constexpr int powm(int p, int i, int m) {
  9.     return i == 0 ? 1 : i % 2 == 0 ? (powm((p * p) % m, i / 2, m)) % m : (p * powm(p, i - 1, m)) % m;
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement