Problem · Bit Manipulation
XOR Multiplication
Learn this problemProblem statement
A new circuit has been designed that takes three inputs: A, B, and N.
The task is to find an integer X such that X < 2^N and the product of (A XOR X) and (B XOR X) is maximized.
Return the result modulo 10^9 + 7.
Note that XOR represents the bitwise XOR operator.
Function
xorMultiplication(A: int, B: int, N: int) → intExamples
Example 1
A = 4B = 6N = 3return = 35We can choose X = 3: (A XOR X) = 7 and (B XOR X) = 5. The product is 35, and 35 modulo 10^9 + 7 is 35.
Constraints
0 <= N <= 301 <= A < 2^N1 <= B < 2^N