319. Bulb Switcher
Description
There are n
bulbs that are initially off. You first turn on all the bulbs, thenyou turn off every second bulb.
On the third round, you toggle every third bulb (turning on if it’s off or turning off if it’s on). For the i^th
round, you toggle every i
bulb. For the n^th
round, you only toggle the last bulb.
Return the number of bulbs that are on after n
rounds.
Example 1:

1 | Input: n = 3 |
Example 2:
1 | Input: n = 0 |
Example 3:
1 | Input: n = 1 |
Constraints:
0 <= n <= 10^9
Hints/Notes
- 2025/02/13 Q3
- math
- Leetcode solution
Solution
Language: C++
1 | class Solution { |