Question: Using java language Write a program to solve the following puzzle: Dr. Z, the ruler of the ancient kingdom of Joejb, has her political foes

Using java language Write a program to solve the following puzzle:

Dr. Z, the ruler of the ancient kingdom of Joejb, has her political foes locked up in individual cells in her dungeon. There is a total of 100 cells. On their Independence Day as all the Joejbians were celebrating, Dr. Z decided to release some of her political prisoners. But being the maverick she is, she does the following:

She goes to the first cell and opens it, she goes to 2nd and opens, and she continues to open the 3rd, 4th ... all the way to the 100th cell.

She then comes back to the 2nd cell and closes it. She closes the 4th and in steps of 2, she closes the 6th, 8th ... 98th and 100th cells.

She then comes to the 3rd cell and this time in steps of 3 she visits each cell (3rd, 6th, 9th ...) and if the cell is open she closes it and if its closed, she opens it.

She repeats this process of opening closed cells and closing open cells in steps of 4, 5 ... all the way up to a step of 100.

In the end, she decrees that all the prisoners in the cells that remain open are free to go.

Who are those lucky prisoners (i.e., what are their cell numbers)?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!