Skip to content

Commit 3340470

Browse files
authored
Create 2939-maximum-xor-product.js
1 parent 81d3a3e commit 3340470

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

2939-maximum-xor-product.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @param {number} a
3+
* @param {number} b
4+
* @param {number} n
5+
* @return {number}
6+
*/
7+
var maximumXorProduct = function(a, b, n) {
8+
let ans = 0n;
9+
let big = 0n;
10+
let found = false;
11+
a = BigInt(a)
12+
b = BigInt(b)
13+
14+
for (let i = 50; i >= 0; i--) {
15+
let curr = BigInt(1) << BigInt(i);
16+
17+
if (((a & curr) == 0n) && ((b & curr) == 0n)) {
18+
if (i < n) ans += curr;
19+
} else if (((a & curr)) && ((b & curr) == 0n)) {
20+
if (big == 0) big = -1;
21+
else if (big == -1 && i < n) ans += curr;
22+
} else if (((a & curr) == 0n) && ((b & curr))) {
23+
if (big == 0) big = 1;
24+
else if (big == 1 && i < n) ans += curr;
25+
}
26+
}
27+
28+
let mod = BigInt(1000000007);
29+
a ^= ans;
30+
b ^= ans;
31+
a %= mod;
32+
b %= mod;
33+
ans = (a * b) % mod;
34+
35+
return Number(ans);
36+
};

0 commit comments

Comments
 (0)