This is a nice brainteaser introduced by Leetcode. Below is a fast method to find integer square root (Credited to stackoverflow)

```
public class Solution {
public int bulbSwitch(int n) {
return isqrt(n);
}
public int isqrt(int n){
long op = n;
long res = 0;
long one = 1 << 30; // The second-to-top bit is set: use 1u << 14 for uint16_t type; use 1uL<<30 for uint32_t type
// "one" starts at the highest power of four <= than the argument.
while (one > op)
{
one >>= 2;
}
while (one != 0)
{
if (op >= res + one)
{
op = op - (res + one);
res = res + 2 * one;
}
res >>= 1;
one >>= 2;
}
return (int) res;
}
}
```

PS: Apparently, we've learned more than if we stopped at just using (int) Math.sqrt(n).