"use strict";functionn(n){returnn>=0?n:-n}functiont(n,t){if("number"==typeofn&&(n=BigInt(n)),"number"==typeoft&&(t=BigInt(t)),n<=0n||t<=0n)thrownewRangeError("a and b MUST be > 0");letr=0n,e=1n,o=1n,i=0n;for(;0n!==n;){constu=t/n,f=t%n,g=r-o*u,p=e-i*u;t=n,n=f,r=o,e=i,o=g,i=p}return{g:t,x:r,y:e}}functionr(t,r){lete="number"==typeoft?BigInt(n(t)):n(t),o="number"==typeofr?BigInt(n(r)):n(r);if(0n===e)returno;if(0n===o)returne;leti=0n;for(;0n===(1n&(e|o));)e>>=1n,o>>=1n,i++;for(;0n===(1n&e);)e>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(e>o){constn=e;e=o,o=n}o-=e}while(0n!==o);returne<<i}functione(n,t){if("number"==typeofn&&(n=BigInt(n)),"number"==typeoft&&(t=BigInt(t)),t<=0n)thrownewRangeError("n must be > 0");constr=n%t;returnr<0n?r+t:r}functiono(n,r){consto=t(e(n,r),r);if(1n!==o.g)thrownewRangeError(`${n.toString()} does not have inverse modulo ${r.toString()}`);returne(o.x,r)}exports.abs=n,exports.bitLength=function(n){if("number"==typeofn&&(n=BigInt(n)),1n===n)return1;lett=1;do{t++}while((n>>=1n)>1n);returnt},exports.eGcd=t,exports.gcd=r,exports.lcm=function(t,e){return"number"==typeoft&&(t=BigInt(t)),"number"==typeofe&&(e=BigInt(e)),0n===t&&0n===e?BigInt(0):n(t/r(t,e)*e)},exports.max=function(n,t){returnn>=t?n:t},exports.min=function(n,t){returnn>=t?t:n},exports.modInv=o,exports.modPow=functiont(r,i,u){if("number"==typeofr&&(r=BigInt(r)),"number"==typeofi&&(i=BigInt(i)),"number"==typeofu&&(u=BigInt(u)),u<=0n)thrownewRangeError("n must be > 0");if(1n===u)return0n;if(r=e(r,u),i<0n)returno(t(r,n(i),u),u);letf=1n;for(;i>0;)i%2n===1n&&(f=f*r%u),i/=2n,r=r**2n%u;returnf},exports.toZn=e;