Number of pairs of numbers with xor equal to X

Правка en1, от Ewwa, 2017-04-21 17:30:18

Hello ! Can somebody explain to me how to solve this problem in O(logn) ? Given N ( N <= 10^18 ) find the number of ordered pairs (a, b) for which a ^ b = X. ( 1 <= a, b <= N ) X is the first number >= N which has all it's bits equal to 1. For example if N = 5(101) then X = 7(111) and if N = 7 then X = 7. Additional challenge : X is any number between 1 and 10^18, independent of N. Problem link if somebody wants to submit : https://www.hackerearth.com/problem/algorithm/roy-and-maximum-xor/

Теги bit manipulation, math

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Ewwa 2017-04-21 17:31:30 8
en1 Английский Ewwa 2017-04-21 17:30:18 544 Initial revision (published)