There are n bulbs in a circle, each bulb has one switch associated with it, on operating the switch, it toggles the state of the corresponding bulb as well as two bulbs adjacent to that one. Given all bulbs are in off state initially, give a plan to turn all bulbs on finally.

Note: n >= 1.

Click here to see the plan

**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.