class Solution:
def maximumXorProduct(self, a: int, b: int, n: int) -> int:
axorx = (a >> n) << n # 低 n 位去掉,剩下的前 m 位就是答案中的 axorb 二进制位。剩下要做的是确定低 n 位具体是多少
bxorx = (b >> n) << n
MOD = 10 ** 9 + 7
for i in range(n-1, -1, -1):
t1 = a >> i & 1
t2 = b >> i & 1
if t1 == t2:
axorx |= 1 << i
bxorx |= 1 << i
else:
if axorx < bxorx:
axorx |= 1 << i # 和一定,两者相差越小,乘积越大
else:
bxorx |= 1 << i
axorx %= MOD
bxorx %= MOD
return (axorx * bxorx) % MOD