Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. def max_xor(l, r)
  2. max = 0
  3.  
  4. (l..r).each do |i|
  5. (i..r).each do |j|
  6. if (i ^ j > max)
  7. max = i ^ j
  8. end
  9. end
  10. end
  11.  
  12. max
  13. end
  14.  
  15. int maximumXOR(int l, int r) {
  16. int q = l ^ r, a = 1;
  17. while(q){
  18. q /= 2;
  19. a <<= 1;
  20. }
  21. return --a;
  22. }
  23.  
  24. def range_xor_max(small, high):
  25. if small == high:
  26. return 0
  27. xor = small ^ high
  28. #how many power of 2 is present
  29. how_many_power_of_2 = math.log(xor, 2)
  30. #we need to make all one's below the highest set bit
  31. return 2**int(math.floor(how_many_power_of_2)+1) - 1
  32.  
  33. def max_xor(L,R):
  34. v = L^R
  35. v |= v >> 1
  36. v |= v >> 2
  37. v |= v >> 4
  38. v |= v >> 8
  39. v |= v >> 16
  40. return b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement