Bulb Switcher
Real-world version: Greenhouse Vent PassesThe statement here is our own: the same inputs, outputs and technique.
A greenhouse roof carries vent_count vents in one long row, numbered 1 through vent_count. Every vent starts shut.
The controller then runs vent_count sweeps over the row. On sweep k it visits each vent whose number is a multiple of k and flips that vent: a shut vent opens and an open vent shuts. Sweep 1 therefore touches every vent, sweep 2 touches vents 2, 4, 6 and so on, up to sweep vent_count, which touches only the last vent.
Return how many vents are open after the final sweep. If vent_count is 0 the roof has no vents and no sweeps are run.
Examples
Example 1
- Input
- vent_count = 8
- Output
- 2
Sweep 1 opens all eight vents, sweep 2 flips the even-numbered ones, and each later sweep flips its own multiples. Two vents are open once sweep 8 has run.
Example 2
- Input
- vent_count = 27
- Output
- 5
Five of the twenty-seven vents are open after the twenty-seventh sweep.
Example 3
- Input
- vent_count = 49
- Output
- 7
Seven of the forty-nine vents are open once every sweep has run.
Constraints
- 0 <= vent_count <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def count_open_vents(vent_count: int) -> int:public int countOpenVents(int ventCount)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's