#include #include #include #include #include #include using namespace std; #define MAX 10000001 long long N; vector insuu; long long insuun=0; long long pc=0; long long ansmin; long long cou=0; map>>> memo; void search2(long long a,long long b,long long c,int sn,int pl){ if(a+b+c>=ansmin){ if(memo.find(a)!=memo.end()&&memo[a].find(b)!=memo[a].end()&&memo[a][b].find(c)!=memo[a][b].end()&&memo[a][b][c].find(sn)!=memo[a][b][c].end()){ memo[a][b][c].erase(sn); if(memo[a][b][c].empty()) memo[a][b].erase(c); if(memo[a][b].empty()) memo[a].erase(b); if(memo[a].empty()) memo.erase(a); } return; } if(memo.find(a)!=memo.end()&&memo[a].find(b)!=memo[a].end()&&memo[a][b].find(c)!=memo[a][b].end()&&memo[a][b][c].find(sn)!=memo[a][b][c].end()){ return; } else{ memo[a][b][c].insert(sn); memo[a][c][b].insert(sn); memo[b][a][c].insert(sn); memo[b][c][a].insert(sn); memo[c][b][a].insert(sn); memo[c][a][b].insert(sn); } if(sn==-1||sn==insuun){ ansmin=min(ansmin,a+b+c); return; } search2(a*insuu[sn],b,c,sn+pl,pl); search2(a,b*insuu[sn],c,sn+pl,pl); search2(a,b,c*insuu[sn],sn+pl,pl); } int main(){ vector arr; vector pn; cin>>N; long long ansmax=N-1; for(long long i=0;i<=MAX;i++){ arr.push_back(true); } arr[0]=false; arr[1]=false; for(long long i=2;i<=MAX;i++){ if(arr[i]){ pn.push_back(i); pc++; for(long long j=i*2;j<=MAX;j+=i){ arr[j]=false; } } } while(!arr.empty()) arr.pop_back(); for(long long i=0;i