


Let 'N' = 4
Then in the first round, all bulbs are on.
In the second round bulbs, 2 and 4 are turned off.
In the third round bulb, 3 is turned off.
In the fourth round bulb, 4 is turned on.
So at the end of 'N' (4) round, only the bulb 1 and 4 is on, so there are 2 good bulbs.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.
Each test case contains an integer 'N' representing the number of bulbs.
For every test case, return an integer denoting the number of good bulbs.
You don’t need to take input or print anything. This already has been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 10^9
Time limit: 1 sec
Approach:
A brute force solution to this problem is to turn on and off the bulbs N time, then at last check the number of bulbs that are on.
Algorithm:
Approach:
But bulb number 16 will be toggled in 1st, 2nd, 4th, 8th, 16th move
Algorithm:
We can use the method of binary search to find the square root of ‘N’.
Algorithm:
First Digit One
Special Digit Numbers
Minimize Maximum Adjacent Distance
Sorted Doubly Linked List to Balanced BST
Minimized Maximum of Products Distributed to Any Store