#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define int long long #define double long double typedef vector VI; typedef pair pii; typedef vector VP; typedef vector VS; typedef priority_queue PQ; templatebool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i, greater > q2; signed main() { cin.tie(0); ios::sync_with_stdio(false); int D; cin >> D; int now = 1; int ans = D; while ((1LL << now) <= D) { int L = 0, R = D; bool ok = 0; while (R - L > 1) { int mid = (R + L) / 2;//最初の飛距離 int m = mid; int dis = mid; REP(i, now) { mid /= 2; dis += mid; } if (mid == 0 || dis < D)L = m; else { R = m; ok = 1; } } int cnt = R; int t = R; REP(i, now) { t /= 2; cnt += t; } if (cnt == D && t)chmin(ans, R); now++; } cout << ans << endl; return 0; }