//嘘解法っぽいものをあえて書いてみる //ただ2分探索をしたら落ちますか? #include #define int long long using namespace std; int f(int x) { int ret = 0; while (x > 0) { ret += x; x >>= 1; } return ret; } bool check(int x, int d) { int ret = 0; while (x > 0) { ret += x; if (ret == d) return true; x >>= 1; } return false; } signed main() { int d; cin >> d; int ng = 0, ok = d, mid; while (ok - ng >= 2) { mid = (ng + ok) / 2; if (f(mid) >= d) ok = mid; else ng = mid; } for (int i = ok; ; i++) { if (check(i, d)) { cout << i << endl; return 0; } } return 0; }