Light Switches
Time limit5sMemory limit128 MB
Decide whether bulb b is on just after time t when each bulb toggles at times dividing its position and every bulb resets to off at time N.
- Level
Hard8 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
A string of lights has bulbs in a row. The bulbs do not blink on and off together. They follow one fixed pattern instead.
At time every bulb is off. At each later integer time , a bulb changes state when its position, counted from the front of the string, is a multiple of . A bulb that is on turns off, and a bulb that is off turns on. So at time every bulb turns on (bulbs ), at time only the even numbered bulbs change again (bulbs ), and at time the bulbs whose position is a multiple of change (bulbs ).
This continues up to time . At time all bulbs are reset to off, so no bulb is on just after time . The pattern then restarts at time , which is the same as time : every bulb turns on.
Quality control is having a hard time checking that the bulbs turn on and off at the right times. Write a verification program that takes the number of bulbs on the strand, a time , and a bulb position , then decides whether that bulb is on or off just after time . A bulb is on just after time when it changed to on at time or was already on before time .
, , and satisfy these limits.
Input
The input has several lines. Each line holds the number of bulbs , the time that has passed since the lights were turned on, and the bulb number you are asked about, separated by spaces. There is no end of data marker, so read until end of file.
Output
For each line, report whether the given bulb is on or off just after the requested time. Follow this format exactly: Case, a space, the case number, a colon and one space, then the answer, which is either On or Off. Do not print trailing spaces.