Problem
Ask
Submissions

Problem: Bulb Switcher

Medium
30 min
Explore the Bulb Switcher problem to understand toggling operations on bulbs through multiple rounds. Learn to apply mathematical and geometric concepts to efficiently solve the problem and determine the final count of bulbs that remain on.

Statement

You are given n bulbs, all initially turned off. You perform n rounds of toggling operations:

  • In round 11, you turn on every bulb.

  • In round 22, you toggle every 2nd2^{nd} bulb.

  • In round 33, you toggle every 3rd3^{rd} bulb.

  • In general, during round i, you toggle every i-th bulb (turning it on if it is off, or turning it off if it is on).

  • In round n, you toggle only the last bulb.

Return the number of bulbs that remain on after all n rounds have been completed.

Constraints:

  • 00 \leq n 109\leq 10^9

Problem
Ask
Submissions

Problem: Bulb Switcher

Medium
30 min
Explore the Bulb Switcher problem to understand toggling operations on bulbs through multiple rounds. Learn to apply mathematical and geometric concepts to efficiently solve the problem and determine the final count of bulbs that remain on.

Statement

You are given n bulbs, all initially turned off. You perform n rounds of toggling operations:

  • In round 11, you turn on every bulb.

  • In round 22, you toggle every 2nd2^{nd} bulb.

  • In round 33, you toggle every 3rd3^{rd} bulb.

  • In general, during round i, you toggle every i-th bulb (turning it on if it is off, or turning it off if it is on).

  • In round n, you toggle only the last bulb.

Return the number of bulbs that remain on after all n rounds have been completed.

Constraints:

  • 00 \leq n 109\leq 10^9