Let be two positive integers. We put a light on each unit square of the table (each light is either on or off). Initially, all the lights are off. In each step, we choose either a column or a row and switch consecutive lights on the chosen column/row. Find the necessary and sufficient condition of such that we can switch on all the lights after finite steps.
Solution
We show that the necessary and sufficient condition of the problem is is divisible by .
The sufficient condition is easy. If is divisible by then is a positive integer. In this case, we can divide the table into rectangles of size . We can easily turn on all of the lights in such a way that turn on one rectangle at the time.
Now we show that is divisible by is also the necessary condition. We color unit squares of the table by colors, denoted by to such that the square is colored by the color . A light on the -colored square is called a -light.
We have the following observation: At each step of implementation, we will change the status of exactly lights, one light in each color. Since all the lights are initially off so after each step, the total lights are switched on of each color are of the same parity. So in order to switch on all the lights, the numbers of lights of each colors must have the same parity. Suppose that is not divisible by , then (). We divide the table into four subtables: , , , .
1) Each of , , is a union of rectangles or rectangles so the number of lights of each color is .
2) In the table , the number of -lights is , and the number of -lights is . Indeed, because then any row contains the light with distinct color. On the other hand, the -lights appear in all the rows of subtable and the -light appears in all the rows of subtable except the first row, then the proof of this case follows.
From 1) and 2), the number of -lights and the number of -lights have different parity, which is a contradiction, then we have completed the problem.