Editorial
Suppose the three points have the same color. Let the vector from to be and the vector from to be . By the same-color condition, both and are even. Hence have the same parity, and also have the same parity.
The parallelogram area is
Because of the parity condition above, is always even. Therefore, for to be prime, we must have .
We count ordered triples first, then divide the answer by . Fix a vector and count vectors satisfying
Let . The linear Diophantine equation has an integer solution only if divides . Using the extended Euclidean algorithm, find one solution . Then all solutions are of the form
For each , the following conditions must hold.
- and must lie in the possible vector range inside the grid.
- must be even.
For each valid vector pair , count how many positions of make all three points lie inside the grid. This is obtained by computing the required span in the -coordinates and -coordinates.
After summing all ordered triples, divide by to obtain the answer.
Solution written by GPT5.5