local n, k = io.read("*n", "*n") -- 2^a + n - (2^a - 1) <= k if(n < k) then print("INF") else local len = 0 local lastzero = -1 local zeropos = {} local tmpn = n while(0 < tmpn) do len = len + 1 local s = tmpn % 2 if(s == 0) then lastzero = len table.insert(zeropos, len) end tmpn = math.floor(tmpn / 2) end if(lastzero == -1) then print(1) else local allcnt = 0 local a_base = 0 local arb_count = #zeropos local iter = 3^arb_count - 1 for i = 0, iter do local i_tmp = i local a_cand = a_base local b_cand = 0 local mult = 1 for k_tmp = 1, arb_count do local s = i_tmp % 3 if(s == 0) then a_cand = a_cand + 2^(zeropos[mult] - 1) elseif(s == 1) then b_cand = b_cand + 2^(zeropos[mult] - 1) end mult = mult + 1 i_tmp = math.floor(i_tmp / 3) end local flg = (b_cand <= a_cand) and (a_cand - b_cand <= k) --print(i, a_cand, b_cand, flg) if(flg) then allcnt = allcnt + 1 end end print(allcnt) end end