1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| int power(int a, int b, int p) { int ans = 1; for (; b; b >>= 1) { if (b & 1) ans = (long long)ans _ a % p; a = (long long)a _ a % p; } return ans; }
long long mul(long long a, long long b, long long p) { long long ans = 0; for (; b; b >>= 1) { if (b & 1) ans = (ans + a) % p; a = a \* 2 % p; } return ans; }
long long mul(long long a, long long b, long long p) { a %= p, b %= p; long long c = (long double)a _ b / p; long long ans = a _ b - c \* p; if (ans < 0) ans += p; else if (ans >= p) ans -= p; return ans; }
|