This page is still under construction.

Parts of this page are still being built. What you see may change.

Light Switches

Time limit5sMemory limit128 MB

Summary
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 NN bulbs in a row. The bulbs do not blink on and off together. They follow one fixed pattern instead.

At time t=0t = 0 every bulb is off. At each later integer time tt, a bulb changes state when its position, counted from the front of the string, is a multiple of tt. A bulb that is on turns off, and a bulb that is off turns on. So at time t=1t = 1 every bulb turns on (bulbs 1,2,3,4,…1, 2, 3, 4, \dots), at time t=2t = 2 only the even numbered bulbs change again (bulbs 2,4,6,8,…2, 4, 6, 8, \dots), and at time t=3t = 3 the bulbs whose position is a multiple of 33 change (bulbs 3,6,9,12,…3, 6, 9, 12, \dots).

This continues up to time t=Nt = N. At time NN all bulbs are reset to off, so no bulb is on just after time NN. The pattern then restarts at time t=N+1t = N + 1, which is the same as time 11: 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 NN on the strand, a time tt, and a bulb position bb, then decides whether that bulb is on or off just after time tt. A bulb is on just after time tt when it changed to on at time tt or was already on before time tt.

NN, tt, and bb satisfy these limits.

  • 3≤N<2543 \le N < 2^{54}
  • 1≤t,b<2541 \le t, b < 2^{54}
  • b≤Nb \le N

Input

The input has several lines. Each line holds the number of bulbs NN, the time tt that has passed since the lights were turned on, and the bulb number bb 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.

Examples1

  1. Example 1

    Input
    55 10 24
    55 68 24
    20 70 5
    
    Expected output
    Case 1: Off
    Case 2: On
    Case 3: Off