!function(n,t){"object"==typeofexports&&"undefined"!=typeofmodule?t(exports):"function"==typeofdefine&&define.amd?define(["exports"],t):t((n="undefined"!=typeofglobalThis?globalThis:n||self).bigintModArith={})}(this,(function(n){"use strict";functiont(n){returnn>=0?n:-n}functione(n,t){if("number"==typeofn&&(n=BigInt(n)),"number"==typeoft&&(t=BigInt(t)),n<=0n||t<=0n)thrownewRangeError("a and b MUST be > 0");lete=0n,r=1n,o=1n,i=0n;for(;0n!==n;){constf=t/n,u=t%n,g=e-o*f,b=r-i*f;t=n,n=u,e=o,r=i,o=g,i=b}return{g:t,x:e,y:r}}functionr(n,e){letr="number"==typeofn?BigInt(t(n)):t(n),o="number"==typeofe?BigInt(t(e)):t(e);if(0n===r)returno;if(0n===o)returnr;leti=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){constn=r;r=o,o=n}o-=r}while(0n!==o);returnr<<i}functiono(n,t){if("number"==typeofn&&(n=BigInt(n)),"number"==typeoft&&(t=BigInt(t)),t<=0n)thrownewRangeError("n must be > 0");conste=n%t;returne<0n?e+t:e}functioni(n,t){constr=e(o(n,t),t);if(1n!==r.g)thrownewRangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);returno(r.x,t)}n.abs=t,n.bitLength=function(n){if("number"==typeofn&&(n=BigInt(n)),1n===n)return1;lett=1;do{t++}while((n>>=1n)>1n);returnt},n.eGcd=e,n.gcd=r,n.lcm=function(n,e){return"number"==typeofn&&(n=BigInt(n)),"number"==typeofe&&(e=BigInt(e)),0n===n&&0n===e?BigInt(0):t(n/r(n,e)*e)},n.max=function(n,t){returnn>=t?n:t},n.min=function(n,t){returnn>=t?t:n},n.modInv=i,n.modPow=functionn(e,r,f){if("number"==typeofe&&(e=BigInt(e)),"number"==typeofr&&(r=BigInt(r)),"number"==typeoff&&(f=BigInt(f)),f<=0n)thrownewRangeError("n must be > 0");if(1n===f)return0n;if(e=o(e,f),r<0n)returni(n(e,t(r),f),f);letu=1n;for(;r>0;)r%2n===1n&&(u=u*e%f),r/=2n,e=e**2n%f;returnu},n.toZn=o}));