319. Bulb Switcher
Input: 3
Output: 1
Explanation:
At first, the three bulbs are [off, off, off].
After first round, the three bulbs are [on, on, on].
After second round, the three bulbs are [on, off, on].
After third round, the three bulbs are [on, off, off].
So you should return 1, because there is only one bulb is on.// A bulb will be on if it is toggled odd times
// Try to find those nubmers with odd number of divisors
// e.g. 1 has 1
// e.g. 4 has 1, 2, 4
// e.g. 9 has 1, 3, 9
// e.g. 16 has 1, 2, 4, 8, 16
// So we are trying to calculate the numbers of square numbers <= n
int bulbSwitch(int n) {
return sqrt(n);
}Last updated