Brain Teaser in C++ - The Circular Jail Cell

This is basically a normal brain teaser question. It started with a problem statement and ended with a solution giving basics knowledge about problem solving.

Originally published in en
Reactions 1
2473
DT
DT 09 Jan, 2020 | 1 min read

Problem Statement:

There is a circular jail with 100 cells numbered 1-100. Each cell has an inmate and the door is

locked. One night the jailor gets drunk and starts running around the jail in circles. In his first

round he opens each door. In his second round he visits every 2nd door (2,4,6---) and shuts the

door. In the 3rd round he visits every 3rd door (3,6,9---) and if the door is shut he opens it, if it

is open he shuts it. This continues for 100 rounds (i.e. 4,8,12 ---; 5,10,15 ---; ---; 49,98 etc.) and

exhausted the jailor falls down. How many prisoners found their doors open after 100 rounds?

Solution:

Round 1: All Doors are Opened

Round 2: Door with multiple of 2 are closed

Round 3: Door with multiple of 3 are closed if open and vice-versa

Round 4: Door with multiple of 4 are closed if open and vice-versa

Similarly, till Round 100 same process would take place

We can conclude that a particular Door "D" would remain open Odd Number of Times.

Solving the problem

Mathematically :

We would calculate Factor for each Number

We would count total number of Factor for each Number

If the number of Factor is even; Door would be closed

If the number of Factor is odd; Door would be open

For Example:

Door No. 12

Factors of 12: 1, 2, 3 ,4 ,6 ,12

Total Number of Factors: 6

Output: Door would be closed

Door No. 36

Factors of 36: 1,2,3,4,6,9,12,18,36

Total Number of Factors: 9

Output: Door would be opened

Conclusion:

We can conclude that the square of the perfect numbers only contain odd number of factors ; as a result of which only 10 doors would be opened.

1 likes

Published By

DT

DT

Comments

Appreciate the author by telling what you feel about the post 💓

Please Login or Create a free account to comment.