eolymp
bolt
Try our new interface for solving problems
Problems

Ackermann Function

published at 1/6/15, 11:45:21 pm

Dear admin, there is a problem with the image-discription of the task. Please, solve this issue. Thanks.

published at 1/3/24, 11:50:34 am

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); }

published at 4/3/24, 1:09:27 am

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();
}

}