/* Problem: 346 - Bytelandian gold coins (From the Sphere Online Judge - http://www.spoj.pl) Author: Andres Mejia-Posada http://blogaritmo.factorcomun.org */ #include #include using namespace std; unsigned long best(const int &n){ static map cache; if (n == 0 || n == 1) return n; unsigned long t = cache[n]; if (t == 0){ t = cache[n] = (n >? (best(n/2) + best(n/3) + best(n/4))); } return t; } int main(){ int n; while (cin >> n){ cout << best(n) << endl; } return 0; }