bigint-mod-arith/dist/bigint-mod-arith-latest.bro...

2 lines
851 B
JavaScript
Raw Normal View History

var bigintModArith=function(a){'use strict';function c(b){return b=BigInt(b),b>=i?b:-b}function d(c,d){c=BigInt(c),d=BigInt(d);let e=i,f=j,g=j,h=i;for(;c!==i;){let a=d/c,b=d%c,i=e-g*a,j=f-h*a;d=c,c=b,e=g,f=h,g=i,h=j}return{b:d,x:e,y:f}}function e(d,e){d=c(d),e=c(e);let f=i;for(;!((d|e)&j);)d>>=j,e>>=j,f++;for(;!(d&j);)d>>=j;do{for(;!(e&j);)e>>=j;if(d>e){let a=d;d=e,e=a}e-=d}while(e);return d<<f}function f(b,a){let c=d(b,a);return c.b===j?h(c.x,a):null}function g(d,e,l){if(l=BigInt(l),d=h(d,l),e=BigInt(e),e<i)return f(g(d,c(e),l),l);let m=j,o=d;for(;0<e;){var p=e%k;e/=k,p==j&&(m*=o,m%=l),o*=o,o%=l}return m}function h(b,c){return c=BigInt(c),b=BigInt(b)%c,0>b?b+c:b}const i=BigInt(0),j=BigInt(1),k=BigInt(2);return a.abs=c,a.eGcd=d,a.gcd=e,a.lcm=function(d,f){return d=BigInt(d),f=BigInt(f),c(d*f)/e(d,f)},a.modInv=f,a.modPow=g,a.toZn=h,a}({});