## DMOPC '14 Exam Time P6 - Math Homework

View as PDF

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem types

One morning, you realize that binary matrices are irresistible. You just can't stop thinking about them. You realize that you had inherited your love of binary matrices from your math teacher, Mr. Sidhu!

Thinking back a little, this is because Mr. Sidhu had left you a homework problem to be completed by last period today. And you didn't even start on it! Luckily, you have a few minutes before class starts. You take a look at the problem again:

Determine the number of binary matrices of size that have at least one 1 entry in each row and column, modulo .

Since there are a lot of problems of this form, specifically of these problems, you would like to write a program that solves these quickly, or risk getting a mark below 100 in math!

#### Input Specification

The first line of input will have the number of test cases, . The next lines will each contain a test case.

Each test case is one line with and separated by a single space.

#### Output Specification

For each test case, output the answer. Remember to take it modulo .

#### Constraints

There will be 5 subtasks each worth 20% of the points for this problem.

#### Tips

Optimize your program to run as fast as possible, even if you think it has the correct complexity.

4
1 1
2 2
2 3
3 2

1
7
25
25

#### Explanation

The seven matrices for the case are:

11
11

11
10

11
01

10
11

01
11

01
10

10
01

Original Problem Author: No_stop; Problem Resource: HDU 5155