luogu#P4921. [MtOI2018] 情侣?给我烧了!
[MtOI2018] 情侣?给我烧了!
Background
FFF.
Enhanced version of this problem: P4931.
Problem Description
There are couples who come to a cinema to watch a movie. In the cinema, there are exactly rows of seats, and each row contains seats, so there are seats in total.
Now, each person will randomly sit in one seat, and all seats will be occupied.
If a couple sits in the same row, then we call this couple harmonious.
Your task is to compute, for , how many different seating arrangements satisfy that there are exactly harmonious couples.
Two seating arrangements are different if and only if there exists at least one person who sits in a different seat in the two arrangements. It is easy to see that there are different seating arrangements in total.
Since the answer may be large, output the result modulo .
Input Format
The input contains multiple test cases.
The first line contains one positive integer , indicating the number of test cases.
The next lines each contain one positive integer .
Output Format
For each test case, output a total of lines. Each line contains one integer, which represents the number of seating arrangements with exactly harmonious couples for .
2
1
2
0
2
16
0
8
Hint
Subtasks
This problem has only one test point with ... so forget brute force!
Source
Problem setter: Imagine.
Translated by ChatGPT 5