Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<map>
- #define long long long
- #define nln '\n'
- using namespace std;
- map<long, long> sav;
- long trade(long n, long a, long b, long c)
- {
- if (n < 12)
- return n;
- if (sav[n] != 0)
- return sav[n];
- 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);
- return sav[n];
- }
- int main()
- {
- //freopen("byteland.inp", "r", stdin);
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- long n;
- while (cin >> n)
- cout << trade(n, n/2, n/3, n/4) << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment