#include using namespace std; #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; typedef long double ld; using P=pair; const ld INF=1e18; const int mod=1e9+7; void solve(){ ll n; cin>>n; ll res=1e18; for(int i=1;i<=1000000;i++){ ll x=1; for(int j=0;j<=30;j++){ ll y=i+n-x+j; if(n-x>=0){ chmin(res,y); } if(x>1000000000000000000/i){break;} x*=i; } } cout<