Given an positive integer n and k. Find maximum xor of 1 to n using at most k numbers. Xor sum of 1 to n is defined as 1 ^ 2 ^ 3 ^ … ^ n.
Input : n = 4, k = 3 Output : 7 Explanation Maximum possible xor sum is 1 ^ 2 ^ 4 = 7. Input : n = 11, k = 1 Output : 11 Explanation Maximum Possible xor sum is 11.
If we have k = 1 then the maximum possible xor sum is 1. Now for k > 1 we can always have an number with its all bits set to 1. So result will be maximum number greater than n with its all bits set to 1.
- Maximum sum by adding numbers with same number of set bits
- Value in a given range with maximum XOR
- Maximum XOR-value of at-most k-elements from 1 to n
- Maximum XOR value in matrix
- Maximum AND value of a pair in an array
- Maximum XOR value of a pair from a range
- Find a sub matrix with maximum XOR
- Find a value whose XOR with given number is maximum
- Maximum value of XOR among all triplets of an array
- Find the maximum subset XOR of a given set
- Find the node whose xor with x gives maximum value
- Maximum 0's between two immediate 1's in binary representation
- Print pair with maximum AND value in an array
- Number whose sum of XOR with given array range is maximum
- Maximum Bitwise AND pair from given range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar