varbigintModArith=function(n){"use strict";functiont(n){returnn>=0?n:-n}functionr(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,m=e-i*u;t=n,n=f,r=o,e=i,o=g,i=m}return{g:t,x:r,y:e}}functione(n,r){lete="number"==typeofn?BigInt(t(n)):t(n),o="number"==typeofr?BigInt(t(r)):t(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}functiono(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}functioni(n,t){conste=r(o(n,t),t);if(1n!==e.g)thrownewRangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);returno(e.x,t)}returnn.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=r,n.gcd=e,n.lcm=function(n,r){return"number"==typeofn&&(n=BigInt(n)),"number"==typeofr&&(r=BigInt(r)),0n===n&&0n===r?BigInt(0):t(n/e(n,r)*r)},n.max=function(n,t){returnn>=t?n:t},n.min=function(n,t){returnn>=t?t:n},n.modInv=i,n.modPow=functionn(r,e,u){if("number"==typeofr&&(r=BigInt(r)),"number"==typeofe&&(e=BigInt(e)),"number"==typeofu&&(u=BigInt(u)),u<=0n)thrownewRangeError("n must be > 0");if(1n===u)return0n;if(r=o(r,u),e<0n)returni(n(r,t(e),u),u);letf=1n;for(;e>0;)e%2n===1n&&(f=f*r%u),e/=2n,r=r**2n%u;returnf},n.toZn=o,n}({});