Skip to content

Latest commit

 

History

History
34 lines (29 loc) · 731 Bytes

File metadata and controls

34 lines (29 loc) · 731 Bytes

The Curious Case Of Benjamin Bulbs

Easy


  1. You are given n number of bulbs. They are all switched off.
  2. A weird fluctuation in voltage hits the circuit n times.
  3. In the 1st fluctuation all bulbs are toggled, in the 2nd fluctuation every 2nd bulb is toggled, in the 3rd fluctuation every 3rd bulb is toggled and so on.
  4. You've to find which bulbs will be switched on after n fluctuations.
  5. Take as input a number n, representing the number of bulbs.
  6. Print all the bulbs that will be on after the nth fluctuation in voltage.

Example 1:

Input:  6
Output:  
1
4

Example 2:

Input:  20
Output:  
1
4
9
16

Constraints:

2 <= n <= 10^9