Let and be positive integers. Consider an square array consisting of lamps that can be in two states - on or off. At the beginning all lamps are turned off.
A move consists of choosing a row or a column of the array and changing the state of consecutive lamps in the chosen row or column, i.e. turning on the lamps that are turned off and vice versa.
Determine the necessary and sufficient condition for which it can be achieved that after a finite number of moves all lamps are turned on. (Tonći Kokan)
Solution
The sought condition is that divides .
It is easy to see that if divides we can choose a sequence of moves after which all lamps will be turned on. Really, if for some positive integer then we choose each row times. In the -th move, for , we choose consecutive lamps from -th to -th place in -th row.
To prove necessity, colour the lamps in colors (named ) in a way presented on the Figure 4.1, i.e. color the lamp in the -th row and -th column in color (mod ).

Figure 4.1: Example of the coloring for .
In every move we change the state of exactly one lamp of each color. In the beginning all lamps are turned off so after each step we have the same number of lamps that are turned on in all colors. If it is possible to achieve that after some move all lamps are turned on, then the number of lamps of each color must be the same.
Assume on the contrary that does not divide and let , where . Divide the array into four subarrays of dimensions and as in the Figure 4.2.
Since each of the subarrays of dimensions and is a disjoint union of sequences of consecutive lamps in a row or a column, we see that the number of lamps of each color in their union is the same (it equals ).
---

Figure 4.2: Dividing the array for , .
Consider the remaining subarray. On Figure 4.3 we see that the number of lamps of color equals , but the number of lamps of color equals . Indeed, the lamps of color appear in each row of the subarray exactly once and the lamps of color appear in each but first row. Also, there is no row with two or more lamps of color because is strictly less than so each row has all the lamps of different color.

Figure 4.3: Example of the subarray for , (and ).
Hence in the whole array we have a different number of lamps of color and color and we can never achieve that all of the lamps are turned on.