/* -*- coding: utf-8 -*- * * 1286.cc: No.1286 Stone Skipping - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100; const int MAX_K = 63; /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ ll check(int k, ll x, ll d) { ll sum = 0; for (int i = 0; x > 0 && i < k; i++, x >>= 1) { sum += x; if (sum > d) return sum; } return sum; } /* main */ int main() { ll d; scanf("%lld", &d); //for (int k = 0; d > 0 && k < MAX_K; k++, d /= 2) printf("%d %lld\n", k, d); ll minx = d; for (int k = 2; k <= MAX_K; k++) { ll x0 = 0, x1 = d; while (x0 + 1 < x1) { ll x = (x0 + x1) / 2; if (check(k, x, d) >= d) x1 = x; else x0 = x; } if (check(k, x1, d) == d && minx > x1) minx = x1; } printf("%lld\n", minx); return 0; }