D = gets.to_i def f(x) len = 0 while x > 0 && len < D len += x x /= 2 end len end ng = 0 ok = 10 ** 18 while (ok - ng).abs >= 2 x = (ok + ng) / 2 if D <= f(x) ok = x else ng = x end end (ok..ok + 1000).each do |x| next if f(x) != D puts x exit end puts D