Skip to content

Commit d963fbb

Browse files
authored
Update 1969-minimum-non-zero-product-of-the-array-elements.js
1 parent af3b50a commit d963fbb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

1969-minimum-non-zero-product-of-the-array-elements.js

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/**
2+
* @param {number} p
3+
* @return {number}
4+
*/
5+
const minNonZeroProduct = function (p) {
6+
const MOD = BigInt(10 ** 9 + 7), bp = BigInt(p)
7+
const bpm = BigInt(1n << bp) - 1n, base = BigInt(1n << bp) - 2n, pow = BigInt(1n << (bp - 1n)) - 1n
8+
return Number((bpm % MOD) * fastPow(base, pow, MOD) % MOD)
9+
10+
}
11+
12+
function fastPow(base, power, mod) {
13+
if(power === 0n) return 1n
14+
base %= mod
15+
let res = fastPow(base, power / 2n, mod)
16+
res = (res * res) % mod
17+
if(power & 1n) res = (res * base) % mod
18+
return res
19+
}
20+
21+
22+
// another
23+
24+
125
/**
226
* @param {number} p
327
* @return {number}

0 commit comments

Comments
 (0)