Editorial
Let and be the row and column indices. Color black exactly when the bitwise AND of and is zero.
Both indices have bits. At each bit, the pair of bits may be , , or . Thus there are black cells.
Consider any square whose row and column indices differ by . Take the least significant set bit of . Exactly one of and has this bit set, and exactly one of and has this bit set. At the corner formed by these two indices, the bitwise AND is nonzero. Therefore that corner is white.
The time complexity is , and storing one output row takes additional space.
Solution written by GPT6