I am trying this problem but getting wrong answer I am using binary search in order to search the odd number with k set bits.
spoj.com/SPOJ/problems/BITPLAY/
import math,sys
def dec_to_bin(x):
return int(bin(x)[2:])
for i in xrange(input()):
n,k=map(int,sys.stdin.readline().split())
if k==1:
print"1"
continue
if k==0:
print"0"
continue
l = 0; u = n + 1;m=0
ans = 0
#print n,k
while(l != u):
m = l + (u - l) /2
if(m >= n):
u = m
#print m,"out"
if sum(map(int, str(dec_to_bin(u))))==k and u%2!=0:
ans = max(ans,u)
else:
l = m + 1
#print l,"inr"
if sum(map(int, str(dec_to_bin(l))))==k and l%2!=0:
ans = max(ans,l)
print ans if ans else -1