Iamtui1010

byteland.cpp

Dec 4th, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<map>
  4.  
  5. #define long long long
  6. #define nln '\n'
  7.  
  8. using namespace std;
  9.  
  10. map<long, long> sav;
  11.  
  12. long trade(long n, long a, long b, long c)
  13. {
  14.     if (n < 12)
  15.         return n;
  16.     if (sav[n] != 0)
  17.         return sav[n];
  18.     sav[n] = trade(a, a/2, a/3, a/4) + trade(b, b/2, b/3, b/4) + trade(c, c/2, c/3, c/4);
  19.     return sav[n];
  20. }
  21.  
  22. int main()
  23. {
  24.     //freopen("byteland.inp", "r", stdin);
  25.     cin.tie(0)->sync_with_stdio(0);
  26.     cout.tie(0)->sync_with_stdio(0);
  27.     long n;
  28.     while (cin >> n)
  29.             cout << trade(n, n/2, n/3, n/4) << nln;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment