Skip to content

Commit 9764281

Browse files
committed
Update Fancy.ts
1 parent 0f02903 commit 9764281

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

fancy-sequence/Fancy.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,22 @@ export default function Fancy(): Fancy {
3636
return { getIndex, multAll, addAll, append };
3737
}
3838

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+
}
4143
const xb = BigInt(x);
4244
const mb = BigInt(mod);
43-
let y = 1n,
44-
m = mb,
45-
p = xb;
45+
let y = 1n, m = mb, p = xb;
4646
m = m - 2n;
4747

4848
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+
}
5052
}
5153
INVERSES[x] = y;
5254
return y;
53-
};
55+
}
5456

5557
const INVERSES: bigint[] = [];

0 commit comments

Comments
 (0)