File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -36,20 +36,22 @@ export default function Fancy(): Fancy {
36
36
return { getIndex, multAll, addAll, append } ;
37
37
}
38
38
39
- const multiplicativeInverse = function ( x : number , mod : bigint ) : bigint {
40
- if ( typeof INVERSES [ x ] !== "undefined" ) return INVERSES [ x ] ;
39
+ function multiplicativeInverse ( x : number , mod : bigint ) : bigint {
40
+ if ( typeof INVERSES [ x ] !== "undefined" ) {
41
+ return INVERSES [ x ] ;
42
+ }
41
43
const xb = BigInt ( x ) ;
42
44
const mb = BigInt ( mod ) ;
43
- let y = 1n ,
44
- m = mb ,
45
- p = xb ;
45
+ let y = 1n , m = mb , p = xb ;
46
46
m = m - 2n ;
47
47
48
48
for ( let i = 0n ; 1n << i < m ; i ++ , p = ( p * p ) % mb ) {
49
- if ( ( ( m >> i ) & 1n ) == 1n ) y = ( y * p ) % mb ;
49
+ if ( ( ( m >> i ) & 1n ) == 1n ) {
50
+ y = ( y * p ) % mb ;
51
+ }
50
52
}
51
53
INVERSES [ x ] = y ;
52
54
return y ;
53
- } ;
55
+ }
54
56
55
57
const INVERSES : bigint [ ] = [ ] ;
You can’t perform that action at this time.
0 commit comments