| 模型 | 模型答案 | 正确答案 |
|---|---|---|
| 金声玉亮2.0 | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 max_product = 0 for x in range(2**n): product = (a ^ x) * (b ^ x) max_product = max(max_product, product) return max_product % MOD ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| deepseek-r1 | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 a_val, b_val = a, b for i in range(n-1, -1, -1): bit = 1 << i mask = (1 << i) - 1 # Calculate products for both options product0 = (a_val | mask) * (b_val | mask) product1 = ((a_val ^ bit) | mask) * ((b_val ^ bit) | mask) if product1 > product0: a_val ^= bit b_val ^= bit elif product1 == product0: # Tie-breaker based on sum of a and b sum0 = (a_val | mask) + (b_val | mask) sum1 = ((a_val ^ bit) | mask) + ((b_val ^ bit) | mask) if sum1 > sum0 or (sum1 == sum0 and ((a_val ^ bit) > a_val or (b_val ^ bit) > b_val)): a_val ^= bit b_val ^= bit return (a_val * b_val) % MOD ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| gpto1 | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 x = 0 difference = 0 for i in range(n - 1, -1, -1): a_i = (a >> i) & 1 b_i = (b >> i) & 1 if a_i == b_i: x_i = 1 - a_i x |= x_i << i # Difference remains the same else: # Try x_i = 0 diff1 = difference + (a_i - b_i) * (1 << i) # Try x_i = 1 diff2 = difference + (b_i - a_i) * (1 << i) if abs(diff1) <= abs(diff2): x_i = 0 difference = diff1 else: x_i = 1 difference = diff2 x |= x_i << i result = ((a ^ x) * (b ^ x)) % MOD return result ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| gpt-4o-2024-08-06 | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 max_value = 0 limit = 1 << n # 2^n for x in range(limit): ax = a ^ x bx = b ^ x product = (ax * bx) % MOD if product > max_value: max_value = product return max_value ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| DeepSeek-Coder-V2-Lite-Instruct | ```python MOD = 10**9 + 7 class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: if a < b: a, b = b, a max_product = 0 for x in range(2**n): product = (a ^ x) * (b ^ x) if product > max_product: max_product = product return max_product % MOD ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| Meta-Llama-3.1-405B-Instruct-Turbo | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 max_val = (1 << n) - 1 max_xor = max_val ^ a max_product = (max_xor ^ a) * (max_xor ^ b) return max_product % MOD ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| Meta-Llama-3.1-70B-Instruct-Turbo | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 max_val = 2**n - 1 max_a = max_b = 0 for i in range(n): bit = 1 << i if a & bit: max_a |= bit if b & bit: max_b |= bit return (max_a * max_b) % MOD ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| Qwen2-72B-Instruct | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 max_product = 0 for i in range(1 << n): x = i product = ((a ^ x) * (b ^ x)) % MOD max_product = max(max_product, product) return max_product ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| baichuan4 | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 mask = (1 << n) - 1 max_xor_a = a ^ mask max_xor_b = b ^ mask return (max_xor_a * max_xor_b) % MOD ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| doubao | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 max_product = 0 for x in range(2**n): product = (a ^ x) * (b ^ x) max_product = max(max_product, product) return max_product % MOD ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| gpto1 | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 x = 0 difference = 0 for i in range(n - 1, -1, -1): a_i = (a >> i) & 1 b_i = (b >> i) & 1 if a_i == b_i: x_i = 1 - a_i x |= x_i << i # Difference remains the same else: # Try x_i = 0 diff1 = difference + (a_i - b_i) * (1 << i) # Try x_i = 1 diff2 = difference + (b_i - a_i) * (1 << i) if abs(diff1) <= abs(diff2): x_i = 0 difference = diff1 else: x_i = 1 difference = diff2 x |= x_i << i result = ((a ^ x) * (b ^ x)) % MOD return result ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| kimi | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10 ** 9 + 7 max_x = 0 for i in range(n): bit_a = a >> i & 1 bit_b = b >> i & 1 if bit_a == bit_b: max_x = (max_x << 1) + 1 else: max_x = max_x << 1 if a >> i & 1 == 0 and b >> i & 1 == 0: max_x += 1 if a >> i & 1 == 1 and b >> i & 1 == 1: max_x += 1 return max_x % MOD ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| minimax | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 # Since we are looking for the maximum value of (a XOR x) * (b XOR x), # we can observe that the maximum value occurs when x has bits set # in positions where a and b have different bits. # We can achieve this by setting x to be the XOR of a and b. # This is because a XOR (a XOR b) = b and b XOR (a XOR b) = a. # Since we want to maximize the product, we want to maximize the XORs. # We can also set the lower n bits of x to 1 to cover all values from 0 to 2^n - 1. x = (a ^ b) | ((1 << n) - 1) # Now we calculate (a XOR x) * (b XOR x) and take modulo 10^9 + 7. result = ((a ^ x) * (b ^ x)) % MOD return result ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| wenxinyiyan | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 max_val = (1 << n) - 1 # If a and b are the same, the maximum product will be when x is the bitwise complement of a (or b) if a == b: return (a ^ max_val) * (b ^ max_val) % MOD # If the most significant bit (MSB) of a and b are different, # then the maximum product will be when x has all bits set to 1 (i.e., max_val) # because XORing with max_val will flip all bits of a and b, resulting in the largest possible values. if (a >> (n - 1)) != (b >> (n - 1)): return (a ^ max_val) * (b ^ max_val) % MOD # If the MSB of a and b are the same, we need to find the highest bit position where a and b differ. # Let's say this bit position is at index 'diff_bit' (from the right, starting at 0). # Then, we can set x to have all bits set to 1 up to (but not including) the diff_bit, # and set the diff_bit to be the same as the corresponding bit in a (or the complement of the bit in b). # This way, XORing a with x will set all bits up to diff_bit to 1, and XORing b with x will set all bits up to diff_bit-1 to 1, # resulting in the maximum possible product. diff_bit = -1 for i in range(n-1, -1, -1): if (a >> i) & 1 != (b >> i) & 1: diff_bit = i break if diff_bit == -1: # If a and b have no differing bits, the maximum product will be when x is the bitwise complement of a (or b) return (a ^ max_val) * (a ^ max_val) % MOD # Construct x based on the diff_bit x = (1 << diff_bit) - 1 if (a >> diff_bit) & 1 == 1: x |= (1 << n) - (1 << (diff_bit + 1)) return (a ^ x) * (b ^ x) % MOD ``` Note: The provided solution attempts to optimize the calculation based on the observation that certain bit patterns of `a` and `b` will result in predictable maximum products. However, due to the complexity of bitwise operations and the potential for edge cases, it is strongly recommended to test this solution with a wide range of inputs to ensure its correctness. Additionally, since the problem statement allows for large inputs (up to 2^50), it is important to use modulo operations (`% MOD`) to prevent integer overflow during calculations. |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| zhipu | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 # Function to find the maximum value of (a XOR x) * (b XOR x) def max_xor_product(a, b, n): max_product = 0 for x in range(2**n): current_product = (a ^ x) * (b ^ x) max_product = max(max_product, current_product) return max_product % MOD return max_xor_product(a, b, n) ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |
| deepseek-v3 | ```python class Solution: def maximumXorProduct(self, a: int, b: int, n: int) -> int: MOD = 10**9 + 7 max_xor = 0 max_product = 0 # Iterate through all possible x values from 0 to 2^n - 1 for x in range(0, 1 << n): a_xor = a ^ x b_xor = b ^ x current_product = (a_xor) * (b_xor) if current_product > max_product: max_product = current_product max_xor = x # Return the maximum product modulo 10^9 + 7 return max_product % MOD ``` |
[{"input": "12\n5\n4", "output": "98", "testtype": "functional"}, {"input": "6\n7\n5", "output": "930", "testtype": "functional"}, {"input": "1\n6\n3", "output": "12", "testtype": "functional"}] |