User's AC Ratio

100.0% (61/61)

Submission's AC Ratio

72.5% (87/120)

Tags

Description

In mathematics, ackermann function is a special kind of recursive function that is not primitive recursive,
which means that you can not re-write the function into iterative form.
Below is the definition of ackermann function:

$A(n, m) =
\begin{align}
\begin{cases}
m + 1 & \textrm{ , if n = 0} \\
A(n - 1, 1) & \textrm{ , if m = 0} \\
A(n - 1, A(n, m - 1)) & \textrm{ , otherwise} \\
\end{cases}
\end{align}
$

Given n and m, please write a program to calculate the value of $A(n, m)$.

Input Format

two integers $n$ and $m$ ($0 \leq n \leq 3$, $0 \leq m \leq 10$), separated by a space

Output Format

an integer which represents $A(n, m)$

Sample Input 1

2 3

Sample Output 1

9

Hints

Problem Source

Subtasks

No. Testdata Range Score
1 0~4 100

Testdata and Limits

No. Time Limit (ms) Memory Limit (KiB) Output Limit (KiB) Subtasks
0 1000 65536 65536 1
1 1000 65536 65536 1
2 1000 65536 65536 1
3 1000 65536 65536 1
4 1000 65536 65536 1