Функция Аккермана
Dear admin, there is a problem with the image-discription of the task. Please, solve this issue. Thanks.
include <bits/stdc++.h>
using namespace std;
int akker(int m, int n) { if (m == 0) { return n + 1; } else if (m > 0 && n == 0) { return akker(m - 1, 1); } else if (m > 0 && n > 0) { return akker(m - 1, akker(m, n - 1)); } }
int main() { int m, n; cin >> m >> n; cout << akker(m, n); }
import java.util.Scanner;
public class Main { public static int calculateResult(int m, int n) { int res; if (m == 0) res = n + 1; else if (m == 1) res = n + 2; else if (m == 2) res = 2 * n + 3; else res = (1 << (n + 3)) - 3; return res; }
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNextInt()) {
int m = scan.nextInt();
int n = scan.nextInt();
int result = calculateResult(m, n);
System.out.println(result);
}
scan.close();
}
}