#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; constexpr ll INF = LLONG_MAX; inline ll saturating_pow(ll a, ll b) { ll res = 1; rep(_, b) { if (res > INF / a) return INF; res *= a; } return res; } inline ll floor_root(ll n, ll k) { ll about = min((long double) INF, powl(n, 1.0l / k)); while (about > 1 && saturating_pow(about, k) > n) --about; while (saturating_pow(about + 1, k) <= n) ++about; return about; } int main() { cin.tie(nullptr)->sync_with_stdio(false); ll n; cin >> n; if (n <= 2) { cout << n << '\n'; return 0; } ll ans = n + 1; for (int j = 2; j <= 60; ++j) { ll i = floor_root(n, j); ll k = n - saturating_pow(i, j); if (k < 0) continue; Debug(i, j, k); ans = min(ans, i + j + k); } cout << ans << '\n'; return 0; }