luogu#P4931. [MtOI2018] 情侣?给我烧了!(加强版)
[MtOI2018] 情侣?给我烧了!(加强版)
Background
FFF.
Original version of this problem: P4921.
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, everyone will randomly sit in one seat, and exactly all seats will be occupied.
If a couple sits in the same row, then we call this couple harmonious.
Your task is to find how many different seating arrangements satisfy that exactly couples are harmonious.
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 not hard to see that there are different seating arrangements in total.
Since the answer may be large, output it modulo .
Input Format
The input contains multiple test cases.
The first line contains one positive integer , the number of test cases.
The next lines each contain two positive integers .
Output Format
Output lines.
For each test case, output one line containing one integer, the number of seating arrangements in which exactly couples are harmonious.
5
1 1
2 0
2 2
2333 666
2333333 1000000
2
16
8
798775522
300377435
Hint
Subtasks
For of the testdata, and .
For of the testdata, .
For of the testdata, , , and .
Source
MtOI2018 迷途の家の水题大赛 T2 Enhanced Version.
Problem setter: Imagine.
Translated by ChatGPT 5