Tap here to switch tabs
Problem
Submissions

Problem: Bulb Switcher

Bulb Switcher starts with n bulbs off and runs n rounds. The first toggles all bulbs, while later rounds toggle every second, third, or later bulb as appropriate. Return how many 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:

  • 0≤0 \leq n ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Bulb Switcher

Bulb Switcher starts with n bulbs off and runs n rounds. The first toggles all bulbs, while later rounds toggle every second, third, or later bulb as appropriate. Return how many 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:

  • 0≤0 \leq n ≤109\leq 10^9