D = gets.to_i def f(x, limit = 1000) len = 0 cnt = 0 while x > 0 && cnt < limit len += x x /= 2 cnt += 1 puts len if limit == 1000 end len end ans = D (1..100).each do |limit| ng = 0 ok = 10 ** 19 while (ok - ng).abs >= 2 x = (ok + ng) / 2 if D <= f(x, limit) ok = x else ng = x end end ans = ok if f(ok, limit) == D && ans > ok end puts ans