Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def max_xor(l, r)
- max = 0
- (l..r).each do |i|
- (i..r).each do |j|
- if (i ^ j > max)
- max = i ^ j
- end
- end
- end
- max
- end
- int maximumXOR(int l, int r) {
- int q = l ^ r, a = 1;
- while(q){
- q /= 2;
- a <<= 1;
- }
- return --a;
- }
- def range_xor_max(small, high):
- if small == high:
- return 0
- xor = small ^ high
- #how many power of 2 is present
- how_many_power_of_2 = math.log(xor, 2)
- #we need to make all one's below the highest set bit
- return 2**int(math.floor(how_many_power_of_2)+1) - 1
- def max_xor(L,R):
- v = L^R
- v |= v >> 1
- v |= v >> 2
- v |= v >> 4
- v |= v >> 8
- v |= v >> 16
- return b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement