#P7415. [USACO21FEB] Count the Cows G
[USACO21FEB] Count the Cows G
Problem Description
As usual, Farmer John’s cows are scattered across his largest pasture. The pasture can be viewed as a huge 2D grid made of square cells (imagine a giant chessboard).
The way the cows are placed on the pasture is quite fascinating. For every cell with and , there is a cow at if, for all integers , the remainders of and when divided by always have the same parity. In other words, the two remainders are either both odd (both equal to ), or both even (equal to or ). For example, among the cells with , the cells containing cows are marked with 1 in the figure below.
x
012345678
0 101000101
1 010000010
2 101000101
3 000101000
y 4 000010000
5 000101000
6 101000101
7 010000010
8 101000101
FJ is interested in the number of cows in a certain region of his pasture. He makes queries, each given by three integers . For each query, FJ wants to know how many cows lie on the diagonal cells from to (inclusive).
Input Format
The first line contains (), the number of queries.
Each of the next lines contains three integers , , and ().
Output Format
Output lines, one line per query.
8
10 0 0
10 0 1
9 0 2
8 0 2
0 1 7
1 1 7
2 1 7
1000000000000000000 1000000000000000000 1000000000000000000
11
0
4
3
1
2
2
1000000000000000001
Hint
Constraints:
- For an additional of the testdata, for each query .
- For an additional of the testdata, for each query and .
- For an additional of the testdata, there are no additional constraints.
Problem by: Benjamin Qi.
Translated by ChatGPT 5