#P9501. 「RiOI-2」likely
「RiOI-2」likely
Background
Little E likes to arrange things in a circle rather than in a chain.
Recently, she learned about plus and minus signs at school. She put them on the circle as a password.
However, she has now forgotten it and only sees a number on the draft paper. What is it?
Problem Description
For a sequence of length that contains only , define $S(a, m) = \displaystyle \sum_{k = 0}^{n - 1} \prod_{l = 0}^{m - 1} a_{(k + l) \bmod n}$.
Given , among the different sequences , find how many different satisfy .
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 three integers, in order: .
Output Format
Output lines. Each line contains one integer, the answer for one test case.
9
4 2 0
9 9 -9
9 3 3
20 8 -12
114 5 14
191 9 81
1036 854 104
998244 353 4
2147483 64 7
12
256
108
10000
661235724
741150826
500003636
222931421
404094315
6
8 4 0
12 4 0
16 4 0
20 4 0
24 4 0
28 4 0
176
1728
26160
368000
5413856
80212608
4
6 2 0
10 2 0
9 9 7
9 3 6
0
0
0
0
Hint
Sample Explanation
For the first test case’s first dataset, the only sequences that do not satisfy the condition are , , , and , so the answer is .
For the first test case’s second dataset, the only sequences that satisfy the condition are those where contains an odd number of , so the answer is .
Constraints and Notes
This problem uses bundled testdata.
| Score | ||||
|---|---|---|---|---|
| / | ||||
| / | / | |||
| / |
For all testdata, it is guaranteed that , , , and .
Translated by ChatGPT 5