From f119a596fe68af4a7c11ca82b7e26b299d5f51ec Mon Sep 17 00:00:00 2001 From: Ariel Date: Sat, 10 Feb 2024 22:57:51 +0800 Subject: [PATCH] Update include.hh --- include.hh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/include.hh b/include.hh index ae13c1e..62a3e50 100644 --- a/include.hh +++ b/include.hh @@ -133,8 +133,23 @@ template ostream& operator<<(ostream& out, vector vec) { #define popback(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.back(); q.pop_back();) #define popfront(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.front();q.pop_front();) -/* algorithms */ +/* math */ +void __exgcd(ll a, ll b, ll& x, ll& y) { + if (b == 0) { + x = 1, y = 0; + return; + } + __exgcd(b, a % b, y, x); + y -= a / b * x; +} +ll inverse(ll a, ll b) { + ll x, y; + __exgcd(a, b, x, y); + return mod(x, b); +} + +/* string algorithms */ vector calc_next(string t) { // pi function of t int n = (int)t.length(); vector pi(n);