Problem C
Grid Magic
Brandon Greg Jr. the number theorist and combinatorist is working on prime numbers in grids. An $n$ by $m$ grid of digits ($0$ to $9$) is called a superprime grid if every non-empty prefix of every row and column (including the full rows and columns) are primes when concatenated.
For example, the following is a superprime grid:
$2$ |
$3$ |
$3$ |
$3$ |
$1$ |
$1$ |
$3$ |
$1$ |
$7$ |
This is because $2$, $23$, $233$, $3$, $31$, $311$, and $317$ are all prime.
Brandon wants to count the number of $n$ by $m$ superprime grids.
Input
The only line of input contains two space-separated numbers $n$ and $m$ ($1\le n, m\le 8$).
Output
Output the number of $n$ by $m$ superprime grids.
Sample Input 1 | Sample Output 1 |
---|---|
1 1 |
4 |
Sample Input 2 | Sample Output 2 |
---|---|
3 2 |
5 |