There is no need to bruteforce it: it is basically a mathematical problem. First you observe that lamps i and 6k+i behave identically so there is no need no include lamps with numbers >=7. Moreover, #6 is identical to #2 and #5 is identical to #3 so throw them away as well. Now we have four lamps at most, and in the case with four lamps, with the given operations only an even number of them (i.e. 0, 2 or 4) can be lit at the same time. Therefore we do not need #4 either since its behavior is totally predictable based on the first three lamps.
And for n<=3 everything can be calculated by hand.