#include using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector #define mat vector > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair pll; typedef long double ld; typedef complex Complex; const ll INF=1e9+7; const ll inf=INF*INF; const int mod=1e9+7; const ll MAX=100010; const double PI=acos(-1.0); signed main(){ ll n;cin>>n; if(n==2){ cout<<3<st; ll ans=n-1; REP(i,2,sqrt(n+1)){ ll now=1; ll sum=0; while(sum<=n){ sum+=now; st.insert(mp(sum,-i)); now*=i; } } vectorp(0); REP(i,2,sqrt(n+1)){ if(n%i==0){ p.pb(i); p.pb(n/i); } } rep(i,p.size()){ auto it=st.lower_bound(mp(p[i],-inf)); if(it==st.end()){ continue; } if((*it).first==p[i]&&(*it).se<-n/p[i]){ ans=min(ans,-(*it).se); } } cout<