Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize "trapv"
- #include<bits/stdc++.h>
- #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
- using namespace std;
- //long long f[1000000001]={0};
- map <long long int,long long int> f;
- long long maxi (long long n)
- {
- auto itr=f.find(n);
- if (itr!=f.end()) return itr->second;
- if (n<=11)
- f.insert(pair<int,int>(n,n));
- else
- f.insert(pair <int,int>(n,max(maxi(n/2)+maxi(n/3)+maxi(n/4),n)));
- //return f[n];
- return (f.find(n))->second;
- }
- signed main()
- {
- faster;
- #ifndef ONLINE_JUDGE
- freopen("ip.txt", "r", stdin);
- freopen("op.txt", "w", stdout);
- #endif
- long long n;
- //int t;cin>>t;
- while(cin>>n)
- {
- cout<<maxi(n)<<endl;
- }
- }
Add Comment
Please, Sign In to add comment