mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
41 lines
1.7 KiB
HTML
41 lines
1.7 KiB
HTML
<p>Given three integers <code>a</code>, <code>b</code>, and <code>n</code>, return <em>the <strong>maximum value</strong> of</em> <code>(a XOR x) * (b XOR x)</code> <em>where</em> <code>0 <= x < 2<sup>n</sup></code>.</p>
|
|
|
|
<p>Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9 </sup>+ 7</code>.</p>
|
|
|
|
<p><strong>Note</strong> that <code>XOR</code> is the bitwise XOR operation.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> a = 12, b = 5, n = 4
|
|
<strong>Output:</strong> 98
|
|
<strong>Explanation:</strong> For x = 2, (a XOR x) = 14 and (b XOR x) = 7. Hence, (a XOR x) * (b XOR x) = 98.
|
|
It can be shown that 98 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2<sup>n</sup><span style="font-size: 10.8333px;">.</span>
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> a = 6, b = 7 , n = 5
|
|
<strong>Output:</strong> 930
|
|
<strong>Explanation:</strong> For x = 25, (a XOR x) = 31 and (b XOR x) = 30. Hence, (a XOR x) * (b XOR x) = 930.
|
|
It can be shown that 930 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2<sup>n</sup>.</pre>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> a = 1, b = 6, n = 3
|
|
<strong>Output:</strong> 12
|
|
<strong>Explanation:</strong> For x = 5, (a XOR x) = 4 and (b XOR x) = 3. Hence, (a XOR x) * (b XOR x) = 12.
|
|
It can be shown that 12 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2<sup>n</sup>.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>0 <= a, b < 2<sup>50</sup></code></li>
|
|
<li><code>0 <= n <= 50</code></li>
|
|
</ul>
|