2939. Maximum Xor Product Medium
1/**
2 * [2939] Maximum Xor Product
3 *
4 * Given three integers a, b, and n, return the maximum value of (a XOR x) * (b XOR x) where 0 <= x < 2^n.
5 * Since the answer may be too large, return it modulo 10^9 + 7.
6 * Note that XOR is the bitwise XOR operation.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: a = 12, b = 5, n = 4
11 * Output: 98
12 * Explanation: For x = 2, (a XOR x) = 14 and (b XOR x) = 7. Hence, (a XOR x) * (b XOR x) = 98.
13 * It can be shown that 98 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2^n<span style="font-size: 10.8333px;">.</span>
14 *
15 * <strong class="example">Example 2:
16 *
17 * Input: a = 6, b = 7 , n = 5
18 * Output: 930
19 * Explanation: For x = 25, (a XOR x) = 31 and (b XOR x) = 30. Hence, (a XOR x) * (b XOR x) = 930.
20 * It can be shown that 930 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2^n.
21 * <strong class="example">Example 3:
22 *
23 * Input: a = 1, b = 6, n = 3
24 * Output: 12
25 * Explanation: For x = 5, (a XOR x) = 4 and (b XOR x) = 3. Hence, (a XOR x) * (b XOR x) = 12.
26 * It can be shown that 12 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2^n.
27 *
28 *
29 * Constraints:
30 *
31 * 0 <= a, b < 2^50
32 * 0 <= n <= 50
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/maximum-xor-product/
38// discuss: https://leetcode.com/problems/maximum-xor-product/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn maximum_xor_product(a: i64, b: i64, n: i32) -> i32 {
44 0
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_2939() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.