```
class Solution {
public:
int bulbSwitch(int n) {
//Basically, it is equivalent to find the largest integer x that x^2<=n (i.e x= int(sqrt(n)); ) using binary search
int left=2, right=n, mid;
if(n<=0) return 0;
while(left<right)
{
mid = (left+right)>>1;
if(mid<=n/mid) left = mid+1;
else right = mid;
}
return left-1;
}
}
```

;