#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll>mp;
ll n;
ll solve(ll n)
{
if(n==0)
return 0;
else
{
if(mp[n])
return mp[n];
else
{
ll t=max(n,solve(n/2)+solve(n/3)+solve(n/4));
mp[n]=t;
return mp[n];
}
}
}
int main()
{
ll i,j,k,l,m,n;
while(cin>>n)
{
mp.clear();
cout<<solve(n)<<endl;
}
return 0;
}
using namespace std;
typedef long long ll;
map<ll,ll>mp;
ll n;
ll solve(ll n)
{
if(n==0)
return 0;
else
{
if(mp[n])
return mp[n];
else
{
ll t=max(n,solve(n/2)+solve(n/3)+solve(n/4));
mp[n]=t;
return mp[n];
}
}
}
int main()
{
ll i,j,k,l,m,n;
while(cin>>n)
{
mp.clear();
cout<<solve(n)<<endl;
}
return 0;
}
No comments:
Post a Comment