fork download
  1. #include <iostream>
  2. #include <cstdint>
  3.  
  4. std::intmax_t F(const std::intmax_t& M, const std::intmax_t& N) {
  5.  
  6. if (M == 0) { return N + 1; }
  7. if (N == 0) { return F(M - 1, 1); }
  8. return F(M - 1, F(M, N - 1));
  9. }
  10.  
  11. int main() {
  12. std::intmax_t M = 0;
  13. std::intmax_t N = 0;
  14. std::intmax_t A = 0;
  15.  
  16. M = 2;
  17. N = 1;
  18. A = F(M, N);
  19. std::cout << "F(" << M << ',' << N << ")=" << A << std::endl;
  20.  
  21. M = 4;
  22. N = 1;
  23. A = F(M, N);
  24. std::cout << "F(" << M << ',' << N << ")=" << A << std::endl;
  25.  
  26. return 0;
  27. }
Time limit exceeded #stdin #stdout 5s 5308KB
stdin
Standard input is empty
stdout
F(2,1)=5