Bell numbers#97

Bell numbers

0.5 seconds
64 megabytes
Very easy

A Bell number \textbf{B}_n is the number of ways to partition a set of elements into disjoint, non-empty subsets. For example, \textbf{B}_3 = 5, because there are possible partitions of the set \{\textbf{a}, \textbf{b}, \textbf{c}\}: \{\{\textbf{a}\}, \{\textbf{b}\}, \{\textbf{c}\}\}, \{\{\textbf{a}, \textbf{b}\}, \{\textbf{c}\}\}, \{\{\textbf{a}, \textbf{c}\}, \{\textbf{b}\}\}, \{\{\textbf{a}\}, \{\textbf{b}, \textbf{c}\}\}, \{\{\textbf{a}, \textbf{b}, \textbf{c}\}\}.

Additionally, \textbf{B}_0 = 1.

Consider the determinant \textbf{D}_n depicted in the following figure:

Given a prime number , find the greatest integer such that \textbf{D}_n is divisible by p^k.

Input

Each line contains two integers and (0 \le n,\, p \le 10000). It is guaranteed that is a prime number.

Output

For each pair and , print on a separate line the greatest integer such that \textbf{D}_n is divisible by p^k.

Examples

Example 1

Loading
Loading