A XOR challenge

3.8

29 votes
Bitmask, Basic Programming, Bit Manipulation, Basics of Bit Manipulation, Greedy Algorithms, Bit manipulation
Problem

You are given an integer such that the XOR of two integers is . In short (⊕ denotes the bitwise the XOR operation).

Out of all possible pairs of and , you must find two integers such that their product is maximum. 

Let us define as the length of in its binary representation. Then, and .

Input format 

A single integer representing ()

Output format 

Print the maximum product you can achieve under the given conditions.

Sample Input
13
Sample Output
70
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The binary representation of 13 is "1101".

We can use A=10 ("1010" in binary) and B=7 ("0111" in binary). This gives us the product 70. No other valid pair (A,B) can give us a larger product.

Editor Image

?