/319. Bulb Switcher

319. Bulb Switcher

Medium
Probability55.6% acceptance

Given an integer total_switches representing the number of switches, each initially off, perform total_switches rounds of toggling. In the i-th round, toggle every switch whose position is divisible by i. Return the count of switches that are on after all rounds.

Example 1

Input: total_switches=5

Output: 2

Explanation: Switches at positions 1 and 4 are on after all rounds.

Example 2

Input: total_switches=10

Output: 3

Explanation: Switches at positions 1, 4, and 9 are on after all rounds.

Constraints

  • 0 <= total_switches <= 109
Python (current runtime)

Case 1

Input: total_switches=7

Expected: 2

Case 2

Input: total_switches=15

Expected: 3

Case 3

Input: total_switches=20

Expected: 4

Case 4

Input: total_switches=25

Expected: 5