File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments