const_ZERO=BigInt(0),_ONE=BigInt(1),_TWO=BigInt(2);functionabs(a){return(a=BigInt(a))>=_ZERO?a:-a}functionbitLength(a){if((a=BigInt(a))===_ONE)return1;letbits=1;do{bits++}while((a>>=_ONE)>_ONE);returnbits}functioneGcd(a,b){if(a=BigInt(a),b=BigInt(b),a<=_ZERO|b<=_ZERO)returnNaN;letx=_ZERO,y=_ONE,u=_ONE,v=_ZERO;for(;a!==_ZERO;){letq=b/a,r=b%a,m=x-u*q,n=y-v*q;b=a,a=r,x=u,y=v,u=m,v=n}return{b:b,x:x,y:y}}functiongcd(a,b){if(a=abs(a),b=abs(b),a===_ZERO)returnb;if(b===_ZERO)returna;letshift=_ZERO;for(;!((a|b)&_ONE);)a>>=_ONE,b>>=_ONE,shift++;for(;!(a&_ONE);)a>>=_ONE;do{for(;!(b&_ONE);)b>>=_ONE;if(a>b){letx=a;a=b,b=x}b-=a}while(b);returna<<shift}asyncfunctionisProbablyPrime(w,iterations=16){return"number"==typeofw&&(w=BigInt(w)),newPromise((resolve,reject)=>{constworker=newWorker(_isProbablyPrimeWorkerUrl());worker.onmessage=event=>{worker.terminate(),resolve(event.data.isPrime)},worker.onmessageerror=event=>{reject(event)},worker.postMessage({rnd:w,iterations:iterations,id:0})})}functionlcm(a,b){returna=BigInt(a),b=BigInt(b),a===_ZERO&&b===_ZERO?_ZERO:abs(a*b)/gcd(a,b)}functionmax(a,b){return(a=BigInt(a))>=(b=BigInt(b))?a:b}functionmin(a,b){return(a=BigInt(a))>=(b=BigInt(b))?b:a}functionmodInv(a,n){if(a==_ZERO|n<=_ZERO)returnNaN;letegcd=eGcd(toZn(a,n),n);returnegcd.b!==_ONE?NaN:toZn(egcd.x,n)}functionmodPow(b,e,n){if((n=BigInt(n))===_ZERO)returnNaN;if(n===_ONE)return_ZERO;if(b=toZn(b,n),(e=BigInt(e))<_ZERO)returnmodInv(modPow(b,abs(e),n),n);letr=_ONE;for(;e>0;)e%_TWO===_ONE&&(r=r*b%n),e/=_TWO,b=b**_TWO%n;returnr}functionprime(bitLength,iterations=16){if(bitLength<1)thrownewRangeError(`bitLength MUST be > 0 and it is ${bitLength}`);returnnewPromise(resolve=>{letworkerList=[];const_onmessage=(msg,newWorker)=>{if(msg.isPrime){for(letj=0;j<workerList.length;j++)workerList[j].terminate();for(;workerList.length;)workerList.pop();resolve(msg.value)}else{letrnd=fromBuffer(randBits(bitLength,!0));try{newWorker.postMessage({rnd:rnd,iterations:iterations,id:msg.id})}catch(error){}}};{letworkerURL=_isProbablyPrimeWorkerUrl();for(leti=0;i<self.navigator.hardwareConcurrency;i++){letnewWorker=newWorker(workerURL);newWorker.onmessage=event=>_onmessage(event.data,newWorker),workerList.push(newWorker)}}for(leti=0;i<workerList.length;i++){letrnd=fromBuffer(randBits(bitLength,!0));workerList[i].postMessage({rnd:rnd,iterations:iterations,id:i})}})}functionprimeSync(bitLength,iterations=16){if(bitLength<1)thrownewRangeError(`bitLength MUST be > 0 and it is ${bitLength}`);letrnd=_ZERO;do{rnd=fromBuffer(randBytesSync(bitLength/8,!0))}while(!_isProbablyPrime(rnd,iterations));returnrnd}functionrandBetween(max,min=_ONE){if(max<=min)thrownewError("max must be > min");constinterval=max-min;letrnd,bitLen=bitLength(interval);do{rnd=fromBuffer(randBits(bitLen))}while(rnd>interval);returnrnd+min}functionrandBits(bitLength,forceLength=!1){if(bitLength<1)thrownewRangeError(`bitLength MUST be > 0 and it is ${bitLength}`);letrndBytes=randBytesSync(Math.ceil(bitLength/8),!1);if(rndBytes[0]=rndBytes[0]&2**(bitLength%8)-1,forceLength){letmask=bitLength%8?2**(bitLength%8-1):128;rndBytes[0]=rndBytes[0]|mask}returnrndBytes}functionrandBytes(byteLength,forceLength=!1){if(byteLength<1)thrownewRangeError(`byteLength MUST be > 0 and it is ${byteLength}`);letbuf;returnnewPromise((function(resolve){buf=newUint8Array(byteLength),self.crypto.getRandomValues(buf),forceLength&&(buf[0]=128|buf[0]),resolve(buf)}))}functionrandBytesSync(byteLength,forceLength=!1){if(byteLength<1)thrownewRangeError(`byteLength MUST be > 0 and it is ${byteLength}`);letbuf;returnbuf=newUint8Array(byteLength),self.crypto.getRandomValues(buf),forceLength&&(buf[0]=128|buf[0]),buf}functiontoZn(a,n){return(n=BigInt(n))<=0?NaN:(a=BigInt(a)%n)<0?a+n:a}functionfromBuffer(buf){letret=_ZERO;for(letiofbuf.values()){letbi=BigInt(i);ret=(ret<<BigInt(8))+bi}returnret}function_isProbablyPrimeWorkerUrl(){letworkerCode=`'use strict';const _ZERO = BigInt(0);const _ONE = BigInt(1);const _TWO = BigInt(2);const eGcd = ${eGcd.toStrin