A hotel has rooms numbered 1 to 1000 One thousand visitors e
A hotel has rooms numbered 1 to 1000. One thousand visitors enter the hotel.
1. The first visitor switches on the light switches of every room.
2. The second visitor switches off the light switches of every other room, starting with room 2.
3. The third visitor toggles the light switches of every third room, starting with room 3, In general, visitor n toggles the switches of every nth room, starting with room n.
After the thousandth visitor, in which rooms are the light switches on? Be sure to justify your answer!
Solution
There are two ways to get solution for this question. First let me go numerically.
Let us give \"I\" when switch is on, and \"O\" when switch is off.
From the table, we can infer that there is a pattern in the lights.
The no. of rooms with lights switched off between two rooms with with lights on are in A.P(Arithmetic Progression)
1st light is on forever, next switch on light is 4th light (2,3 are off), next 9th room is on (5,6,7,8 are off)
similarly next 6 rooms are off and then 8 and so on.
Rooms with lights on are 1,4,9,16,25,36,49,64,81,100,121, 144, 169, 196.... all square numbers upto 1000
Now, by second method we\'ll make it theoretically.
If nth visitor, toggles every nth switch.. by deifinition it means he toggles all multiples of n upto 1000.
as 1st visitor switches on all the lights, lets start from there.
Prime numbers are not multiples of any number, so they get switched off/ toggled only when that numbered visitor toggles switches. So prime numbers always stays switched off.
If a number has even number of factors other than 1 and itself, then it is switched off.
Then remaining only rooms with lights on are numbers with odd number of factors other than 1 and itself.
and by theory, no number other than perfect squares has odd number of factors. Thus all perfect squars fromm 1 to 1000 are swtched on after 1000th visitor enters room.
| switches | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1st visitor | I | I | I | I | I | I | I | I | I | I | I | I | I | I | I | I | I | I | I | I | 
| 2nd visitor | I | O | I | O | I | O | I | O | I | O | I | O | I | O | I | O | I | O | I | O | 
| 3rd Visitor | I | O | O | O | I | I | I | O | O | O | I | I | I | O | O | O | I | I | I | O | 
| 4th visitor | I | O | O | I | I | I | I | I | O | O | I | O | I | O | O | I | I | I | I | I | 
| 5th visitor | I | O | O | I | O | I | I | I | O | I | I | O | I | O | I | I | I | I | I | O | 
| 6th Visitor | I | O | O | I | O | O | I | I | O | I | I | I | I | O | I | I | I | O | I | O | 
| 7th visitor | I | O | O | I | O | O | O | I | O | I | I | I | I | I | I | I | I | O | I | O | 
| 8th visitor | I | O | O | I | O | O | O | O | O | I | I | I | I | I | I | O | I | O | I | O | 
| 9th Visitor | I | O | O | I | O | O | O | O | I | I | I | I | I | I | I | O | I | I | I | O | 
| 10th visitor | I | O | O | I | O | O | O | O | I | O | I | I | I | I | I | O | I | I | I | I | 
| 11th visitor | I | O | O | I | O | O | O | O | I | O | O | I | I | I | I | O | I | I | I | I | 
| 12th visitor | I | O | O | I | O | O | O | O | I | O | O | O | I | I | I | O | I | I | I | I | 
| 13th visitor | I | O | O | I | O | O | O | O | I | O | O | O | O | I | I | O | I | I | I | I | 
| 14th visitor | I | O | O | I | O | O | O | O | I | O | O | O | O | O | I | O | I | I | I | I | 
| 15th visitor | I | O | O | I | O | O | O | O | I | O | O | O | O | O | O | O | I | I | I | I | 
| 16th visitor | I | O | O | I | O | O | O | O | I | O | O | O | O | O | O | I | I | I | I | I | 
| 17th visitor | I | O | O | I | O | O | O | O | I | O | O | O | O | O | O | I | O | I | I | I | 
| 18th visitor | I | O | O | I | O | O | O | O | I | O | O | O | O | O | O | I | O | O | I | I | 
| 19th visitor | I | O | O | I | O | O | O | O | I | O | O | O | O | O | O | I | O | O | O | I | 
| 20th visitor | I | O | O | I | O | O | O | O | I | O | O | O | O | O | O | I | O | O | O | O | 


