Guest User

Untitled

a guest
May 2nd, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #pragma GCC optimize "trapv"
  2. #include<bits/stdc++.h>
  3. #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
  4. using namespace std;
  5. //long long f[1000000001]={0};
  6. map <long long int,long long int> f;
  7.  
  8. long long maxi (long long n)
  9. {
  10. auto itr=f.find(n);
  11. if (itr!=f.end()) return itr->second;
  12. if (n<=11)
  13. f.insert(pair<int,int>(n,n));
  14. else
  15. f.insert(pair <int,int>(n,max(maxi(n/2)+maxi(n/3)+maxi(n/4),n)));
  16. //return f[n];
  17. return (f.find(n))->second;
  18. }
  19.  
  20. signed main()
  21. {
  22. faster;
  23. #ifndef ONLINE_JUDGE
  24. freopen("ip.txt", "r", stdin);
  25. freopen("op.txt", "w", stdout);
  26. #endif
  27. long long n;
  28. //int t;cin>>t;
  29. while(cin>>n)
  30. {
  31. cout<<maxi(n)<<endl;
  32. }
  33. }
Add Comment
Please, Sign In to add comment