Thanks for your smart solution! The following is my attempt to understand it.

The four buttons correspond to four kinds of numbers:

x % 2 == 1 && x % 3 == 1, such as x == 1;

x % 2 == 1 && x % 3 != 1, such as x == 3;

x % 2 == 0 && x % 3 == 1, such as x == 4;

x % 2 == 0 && x % 3 != 1, such as x == 2.

There are eight independent button operations (suppose the initial status is on, on, on, on) : 1 (off, off, off, off), 2 (on, off, on, off), 3 (off, on, off, on), 4 (off, on, on, off), 1 + 4 (on, off, off, on), 2 + 4 (off, off, on, on), 3 + 4 (on, on, off, off), 1 + 2 + 3 == 3 + 3 (on, on, on, on), because 1 + 2 == 3, 2 + 3 == 1, 1 + 3 == 2, 1 + 2 + 4 == 3 + 4， 2 + 3 + 4 == 1 + 4，1 + 3 + 4 == 2 + 4， 1 + 2 + 3 + 4 == 3 + 3 + 4 == 4. The first operation changes all bulbs simultaneously, the eighth brings no change at all, the rest six operations always flip two bulbs together, so there are only three independent bulbs among the four kinds. We only need analyze cases for n = 1, 2, 3.

When m == 0, nothing happens, there is only one status;

when n == 1, the bulb can be kept "on" as a result of button operation 2, or switched "off" as a result of operation 1 or 3 or 4. Operation 2 equals operation 1 plus operation 3, operation 3 equals the combination of operation 1 and 2, operation 1 is equal to operation 2 plus 3. Therefore we can get the same status after both odd and even operations. Case n == 1 always yields 2;

when n == 2, there are four possible status, "on, off" == operation 2 or 1 + 3, "off, on" == 3 or 1 + 2, "off, off" == 1 or 2 + 3, "on, on" == 1 + 1 == 2 + 3 + 1 == 1 + 3 + 3 + 1 == ... or 2 + 2 or 3 + 3 or 4 + 4. Except status "on, on" which can be reached only after 2 or more operations, all the rest status can be obtained through both odd and even operations;

When n == 3, eight distinct status are possible. Using the same trick, we can find there are only two special cases: m == 1 and m == 2, all the other cases yield the same result 8.