eolymp
bolt
Try our new interface for solving problems
Problems

Complete Tree Labeling

Complete Tree Labeling

A complete \textbf{k}-ary tree is a \textbf{k}-ary tree in which all leaves have same depth and all internal nodes have degree \textbf{k}. This \textbf{k} is also known as the branching factor of a tree. It is very easy to determine the number of nodes of such a tree. Given the depth and branching factor of such a tree, you will have to determine in how many different ways you can number the nodes of the tree so that the label of each node is less that that of its descendants. You should assume that for numbering a tree with \textbf{N} nodes you have the (\textbf{1}, \textbf{2}, \textbf{3}, \textbf{N}-\textbf{1}, \textbf{N}) labels available. \InputFile The input file will contain several lines of input. Each line will contain two integers \textbf{k} and \textbf{d}. Here \textbf{k} is the branching factor of the complete \textbf{k}-ary tree and \textbf{d} is the depth of the complete \textbf{k}-ary tree (\textbf{k}>\textbf{0}, \textbf{d}>\textbf{0}, \textbf{k}*\textbf{d}<=\textbf{21}). \OutputFile For each line of input, produce one line of output containing a round number, which is the number of ways the \textbf{k}-ary tree can be labeled, maintaining the constraints described above.
Time limit 8 seconds
Memory limit 64 MiB
Input example #1
2 2
10 1
Output example #1
80
3628800