#P9554. 「CROI · R1」浣熊的溪石
「CROI · R1」浣熊的溪石
Background
Looking back to the past, the sky was clear, the sun was warm, and the breeze was gentle.
Creek stones, with different depths and heights, were scattered in the crystal-clear Mengfeng Creek like jade.
The endless fun memories of raccoons doing parkour on the water also began here...
Problem Description
As the sun rises and the moon sets, spring goes and autumn comes, the heights of the Mengfeng creek stones change in countless ways.
The thoughtful little raccoon CleverRaccoon wants to find out how many different height sequences these creek stones can form.
Now there are some non-negative integer sequences of length .
When , take values in , and the other elements take values in , where .
When , takes values in .
Definition: Sequences are considered the same if and only if either or .
Given , find the maximum number of different sequences. Output the answer modulo .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
The next lines each contain two positive integers separated by spaces, with meanings as described above.
Output Format
Output lines. For each test case, output one positive integer, the answer modulo .
3
1 3
2 2
6 3
5
6
666
Hint
Explanation #1
When , , so there are different height sequences in total.
When , there are different height sequences in total, listed as follows:
| Index | ||
|---|---|---|
Constraints
This problem uses bundled Subtasks.
| Subtask | Special Property | Score | |||
|---|---|---|---|---|---|
| None | |||||
| None | |||||
| is odd | |||||
| is even | |||||
| None | |||||
For of the testdata, it is guaranteed that .
Translated by ChatGPT 5