The idea is to check the value of n%3, there can be three cases

**Case 1: when n%3 = 0, bulbs are complete multiple of 3**

This is the simplest case, here assume n/3 pairs of bulbs and operate the middle bulb from each pair, ultimately all n bulbs will be on.

**Case 2: when n%3 = 1, case 1 + one extra bulb**

In this case, if we reach to a state where only one bulb is on and remaining n-1 bulbs are off, we can turn on remaining n-1 bulbs easily as (n-1) is complete multiple of 3.

Lets assume n =7, and do as described in step 1 to 5.

Step 1: Toggle bulbs in pair of 3, 2nd, 5th, till n-2th bulb. at this stage only nth bulb will be off and rest all will be in on state.

Step 2: Toggle 1st bulb, it will make 1st and 2nd bulb off and nth bulb(7th for our example) ON.

Step 3: Toggle 3rd bulbs, it will make 1st, 2nd and 4th bulbs off and remaining bulbs ON.

Step 4: Leave 1st,2nd,3rd and 4th bulbs as it is and turn off remaining (n-4) bulbs in pair of 3′s. as (n-4) is complete power of 3 this can be done easily as in case 1. after this only 2nd bulbs will be ON.

Step 5: Leave 2nd bulb and turn on remaining (n-1) bulbs in pair of 3′s, again as (n-1) is complete multiple of 3, this can be done easily as in case 1. at this point all bulbs will be ON.

**Case 3: when n%3 = 2, case 1 + two extra bulbs**

In this case, if we reach to a state where only two bulbs are on and remaining n-2 bulbs are off, we can turn on remaining n-2 bulbs easily as (n-2) is complete multiple of 3.

Lets assume n =8, and do as described in step 1 to 5.

Step 1: Toggle bulbs in pair of 3, 2nd, 5th, till (n-3)th bulb. at this stage only nth and (n-1)th bulbs will be off and rest all will be in on state.

Step 2:Toggle nth bulb, (8th for our case), this will leave only 1st bulb off, rest all ON.

Step 3: Leave 1st and nth bulb and turn off remaining (n-2) bulbs in pair of 3′s, as (n-2) is complete multiple of 3

Step 4: Toggle nth bulb again, this will turn on 1st and 2nd bulb and remaining all will be off.

Step 5: Leave 1st and 2nd bulb and turn on remaining (n-2) bulbs in pair of 3′s, as (n-2) is a complete power of 3, it can be done easily as in case 1.

Source: http://puzzlersworld.com/interview-puzzles/n-bulbs-in-a-circle-puzzle/#more-2917