Snapper Chain (Small)
InterviewTime limit5sMemory limit512 MB
Decide whether N chained toggle switches all turn on after K snaps, which lights the bulb.
- Level
Easy3 of 10
- Topics
- Bit manipulation, Simulation
- Solved
- No attempts yet
Problem
A Snapper is a small electrical device with an input plug on one side and an output socket on the other. The output socket takes a device such as a light bulb, or the input plug of another Snapper.
A Snapper is either ON or OFF. Power leaves the output socket only while the Snapper is ON and its input plug is receiving power. When you snap your fingers, every Snapper that is receiving power at that moment swaps ON for OFF and OFF for ON.
One day I bought Snappers, plugged the first one into a wall power socket, plugged the second one into the output socket of the first, and kept going that way down the chain. Then I attached a light bulb to the output socket of the -th Snapper.
At the start every Snapper is OFF, only the first one receives power, and the bulb is dark. After one snap the first Snapper turns ON and power reaches the second Snapper. After a second snap the first and the second Snapper both flip, so the second one is ON but receives no power. The third snap flips only the first Snapper, so the first and the second are both ON. Had a bulb been attached to the output socket of the second Snapper, it would light up.
I kept snapping for hours. Decide whether the bulb is lit after snaps. The bulb is an ordinary one with no tricks, so it lights only while the Snapper directly in front of it supplies power.
Input
The first line contains the number of test cases . Each of the next lines contains two integers and .
Constraints
Output
For each test case print one line in the form Case #X: Y. Here is the test case number starting from 1, and is ON if the bulb is lit and OFF if it is dark.