Skip to content

Commit af3b50a

Browse files
authored
Create 1969-minimum-non-zero-product-of-the-array-elements.js
1 parent 0749af8 commit af3b50a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {number} p
3+
* @return {number}
4+
*/
5+
const minNonZeroProduct = function (p) {
6+
const b = BigInt(p)
7+
const mod = BigInt(10 ** 9 + 7)
8+
9+
return (
10+
(((BigInt(1n << b) - 1n) % mod) *
11+
pow(BigInt(1n << b) - 2n, BigInt(1n << (b - 1n)) - 1n)) %
12+
mod
13+
)
14+
15+
function pow(a, n) {
16+
let r = 1n
17+
a %= mod
18+
while (n > 0n) {
19+
r = (r * a) % mod
20+
a = (a * a) % mod
21+
n /= 2n
22+
}
23+
return r
24+
}
25+
}

0 commit comments

Comments
 (0)