2 lines
1.5 KiB
JavaScript
2 lines
1.5 KiB
JavaScript
|
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).bigintModArith={})}(this,(function(n){"use strict";function t(n){return n>=0?n:-n}function e(n,t){let e=BigInt(n),r=BigInt(t);if(e<=0n||r<=0n)throw new RangeError("a and b MUST be > 0");let i=0n,o=1n,f=1n,u=0n;for(;0n!==e;){const n=r/e,t=r%e,c=i-f*n,g=o-u*n;r=e,e=t,i=f,o=u,f=c,u=g}return{g:r,x:i,y:o}}function r(n,e){let r=BigInt(t(n)),i=BigInt(t(e));if(0n===r)return i;if(0n===i)return r;let o=0n;for(;0n===(1n&(r|i));)r>>=1n,i>>=1n,o++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&i);)i>>=1n;if(r>i){const n=r;r=i,i=n}i-=r}while(0n!==i);return r<<o}function i(n,t){const e=BigInt(t);if(t<=0)return NaN;const r=BigInt(n)%e;return r<0n?r+e:r}function o(n,t){try{const r=e(i(n,t),t);return 1n!==r.g?NaN:i(r.x,t)}catch(n){return NaN}}n.abs=t,n.bitLength=function(n){if(1n===(n=BigInt(n)))return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},n.eGcd=e,n.gcd=r,n.lcm=function(n,e){const i=BigInt(n),o=BigInt(e);return 0n===i&&0n===o?BigInt(0):t(i*o)/r(i,o)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modInv=o,n.modPow=function n(e,r,f){const u=BigInt(f);if(u<=0n)return NaN;if(1n===u)return BigInt(0);let c=i(e,u);if((r=BigInt(r))<0n)return o(n(c,t(r),u),u);let g=1n;for(;r>0;)r%2n===1n&&(g=g*c%u),r/=2n,c=c**2n%u;return g},n.toZn=i,Object.defineProperty(n,"__esModule",{value:!0})}));
|