#include #include #include using namespace std; double get_cpu_time() { rusage ruse; getrusage(RUSAGE_SELF, & ruse); return ruse.ru_utime.tv_sec + ruse.ru_utime.tv_usec / 1000000.0 + ruse.ru_stime.tv_sec + ruse.ru_stime.tv_usec / 1000000.0; } long long int calls; int A(int m, int n) { calls += 1; if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m, n - 1)); } int main(int argc, char * argv[]) { int m = atol(argv[1]); int n = atol(argv[2]); calls = 0; double t1 = get_cpu_time(); int r = A(m, n); double t2 = get_cpu_time(); cout << "result: " << r << "\n"; cout << "calls: " << calls << "\n"; cout << "time: " << t2 - t1 << "\n"; }