#P4067. [SDOI2016] 储能表
[SDOI2016] 储能表
Description
There is a table with rows and columns, with rows numbered from to and columns numbered from to . Each cell stores energy. Initially, the cell in row and column stores units of energy (where denotes bitwise XOR). Therefore, the total energy stored in the whole table is
As time passes, the energy in the cells gradually decreases. After each unit of time, the energy in every cell decreases by . Obviously, once a cell’s energy decreases to , it will not decrease any further.
That is, after units of time, the total energy stored in the whole table is
$$\sum_{i=0}^{n-1} \sum_{j=0}^{m-1} \max((i \oplus j)-k,0).$$Given the table, find the total energy it stores after units of time.
Since the total energy may be large, output it modulo .
Input Format
The first line contains an integer , the number of test cases. Then lines follow, each containing four integers .
Output Format
Output lines, each containing one number: the result of the total energy modulo .
3
2 2 0 100
3 3 0 100
3 3 1 100
2
12
6
Hint
For of the testdata, it is guaranteed that , , , .
| 测试点编号 | |||||
|---|---|---|---|---|---|
Translated by ChatGPT 5
京公网安备 11011102002149号