Saturday, 2 March 2013

100 student and 1000 door problem

Description:There was 100 students and 1000 closed doors. The 1st student opens all 1000 doors, the 2nd student closes doors 2,4,6,8,10, etc., the 3rd student opens doors closed and closes doors opened on doors 3,6,9,12,15,etc.
after going all of 100 students how many doors are still open?


Answer is 524

How to get it? what are these numbers? What are the properties of these numbers? Do you want to know it?
1) 1 st consider first 100 doors.
     Only 10 doors are open after passing all students.
 door number       students number
     1                     (1)
     4                     (1, 2, 4)
     9                     (1, 3, 9)
    16                     (1, 2, 4, 8, 16)
    25                     (1, 5, 25)
    36                     (1, 2, 3, 4, 6, 9, 12, 18, 36)
    49                     (1, 7, 49)
    64                     (1, 2, 4, 8, 16, 32, 64)
    81                     (1, 3, 9, 27, 81)
   100                     (1, 2, 4, 5, 10, 20, 25, 50, 100)
 
    These are Square Number 

  • Student 1 can open all the doors.
  • The Students whose number is same as door's number they  are  close the doors. 
  • If the door number is prime it can't open by other students.Because it can't have other divisors. 
  • If the door number is composite number and it is not a square number then these doors are closed after passing all students. Because door number = M x N. If M is open the door then N is closed it. Let door number is 10. 10= 2 x 5, 2 open the door and 5 close that door. Let door number is 20 , 20 = 2 x 10,4 x 5. Here 2 open the door and 10 close that door, 4 open the door and 5 close that door.
  • If the door number is composite number and it is a square number then these doors are opened after passing all students. Because one pair of divisor is in the form of N x N.  Let door number is 25.  25 = 5 x 5. Here student 5 open the door. Let door number is 16.  16 = 2 x 8, 4 x 4. Here student 2 open the door student 8 close it and student 4 open it.
    Only 10 doors are open after passing all students.

2) Consider doors 101 to 200
       All factors of door's number are less than 101. Here student 1 open all doors, and if another student    (number M)   can close the door there exist a student (number N) can open it. But in the case of              Square Numbers M=N therefore door remains closed.  96 doors are remains  open after passing all         students. Door number 121,144,169 and 196(square numbers) are remains closed.

    96 doors are remains  open after passing all students.

3) Consider doors 201 to 300
      ->If door's number is odd, then all factors of door's number are less than 101. Here student 1 open all doors, and if another student  (number M)  can close the door there exist a student (number N)   can open it. But in the case of   Square Numbers M=N therefore door remains closed. 48 doors are remains  open after passing all  students. Door number 225 and 289(square numbers) are remains closed.
     ->If door's number is even, one of the factors of door's number is grater than 101. Here student 1open all doors, and student 2 closed all doors.  If another student  (number M !=2)  can open the             door there exist a student  (number N!=2)   can close it. But in the case of   Square Numbers M=N therefore door remains  open.  There was is only 1 square number 256. Only 1 door is remains  open after passing all  students.

      49 doors are remains  open after passing all  students.
4)  Consider doors 301 to 400
        ->If door's number is not a multiple of 2 or 3, then all factors of door's number are less than 101. Here student 1 open  all doors, and if another student  (number M)  can close the door there exist a student (number N)   can open it. But in the case of   Square Numbers M=N therefore door remains closed. 32 doors are remains  open after passing all  students. Door number 361(square number) is remains closed.
     ->If door's number is multiple of 6, two of the factors of door's number is grater than 101(2 x N and 3 x N). Here student 1open all doors, student 2 closed all doors, and student 3 open all doors.  If another student  (number M !=2 or 3)  can close the   door there exist a student  (number N!=2 or 3)   can open it. But in the case of   Square Numbers M=N therefore door remains  close.  There is only 1 square number 324. 15 door is remains  open after passing all  students.
    ->If door's number is multiple of 2 and not multiple of 3, one of the factors of door's number is grater than 101(2 x N). Here student 1 open all doors, and student 2 closed all doors.  If another student  (number M !=2)  can open the   door there exist a student  (number N!=2)   can close it. But in the case of   Square Numbers M=N therefore door remains  open.  There is only 1 square number 400. Only 1 door is remains  open after passing all  students.
    ->If door's number is multiple of 3 and not multiple of 2, one of the factors of door's number is grater than 101(3 x N). Here student 1 open all doors, and student 3 closed all doors.  If another student  (number M !=3)  can open the   door there exist a student  (number N!=3)   can close it. But in the case of   Square Numbers M=N therefore door remains  open.  There is no such square number. all doors are remains  close after passing all  students.

48 doors are remains  open after passing all  students.



5)  Consider doors 401 to 500
        ->If door's number is not a multiple of 2 or 3 or 4, then all factors of door's number are less than 101. Here student 1 open  all doors, and if another student  (number M)  can close the door there exist a student (number N)   can open it. But in the case of   Square Numbers M=N therefore door remains closed. There is no such square number. 34 doors are remains  open after passing all  students. 
     ->If door's number is multiple of 2 and 3 not multiple of 4, two of the factors of door's number is grater than 101(2 x N and 3 x N). Here student 1 open all doors, student 2 closed all doors, and student 3 open all doors.  If another student  (number M !=2 or 3)  can close the   door there exist a student  (number N!=2 or 3)   can open it. But in the case of   Square Numbers M=N therefore door remains  close.  There is no such square number. 9 door is remains  open after passing all  students.
->If door's number is multiple of 2 and 4 not multiple of 3, two of the factors of door's number is grater than 101(2 x N and 4 x N). Here student 1 open all doors, student 2 closed all doors, and student 4 open all doors.  If another student  (number M !=2 or 3)  can close the   door there exist a student  (number N!=2 or 4)   can open it. But in the case of   Square Numbers M=N therefore door remains  close.  There is only 1 square number 484. 16 door is remains  open after passing all  students.
    ->If door's number is multiple of 2 and not multiple of 3 or 4, one of the factors of door's number is grater than 101(2 x N). Here student 1 open all doors, and student 2 closed all doors.  If another student  (number M !=2)  can open the   door there exist a student  (number N!=2)   can close it. But in the case of   Square Numbers M=N therefore door remains  open.  There is no such square number.
    ->If door's number is multiple of 3 and not multiple of 2, one of the factors of door's number is grater than 101(3 x N). Here student 1 open all doors, and student 3 closed all doors.  If another student  (number M !=3)  can open the   door there exist a student  (number N!=3)   can close it. But in the case of   Square Numbers M=N therefore door remains  open.  Door number 441(square number) is remains open.door remains  open after passing all  students.

60 doors are remains  open after passing all  students.

Apply above method to get all such numbers.
6)  Consider doors 501 to 600
       53
7)  Consider doors 601 to 700
        54
8)  Consider doors 701 to 800
      53
9)  Consider doors 801 to 900
        48
10)  Consider doors 901 to 1000
       53
  
  What are the properties of these numbers?
   1. Prime test.
           All prime number between 100 to 1000 are include in this set.
   2. Square number.
           All square number less than 100  include in this set.
   3. Properties of single set(set contain 100 elements):
             - >101 to 200  hset(),                                      sset(121,144,169,196)
             - >201 to 300  hset(2),                                    sset(225,256,289)
             - >301 to 400  hset(2,3),                                 sset(324,361,400)
             - >401 to 500  hset(2,3,4),                              sset(441,484)
             - >501 to 600  hset(2,3,4,5),                           sset(529,576)
             - >601 to 700  hset(2,3,4,5,6),                        sset(625,676)
             - >701 to 800  hset(2,3,4,5,6,7),                     sset(729,784)
             - >801 to 900  hset(2,3,4,5,6,7,8),                  sset(841)
             - >901 to 1000  hset(2,3,4,5,6,7,8,9),             sset(900,961)
     

   Let M be the door's number>100  ,    
        if M is open after passing all  students,
           
                then 
conditions:     

                          1) Odd number of elements in hset is factor of M and M is in sset.                               

                                    OR


                          2) Zero or even number of elements in hset is factor of M and M is not in sset






List of all open door with students who open or close that door, And Python code to find these numbers is given below.

       
# To store status of each door 1 stands for closed -1 stands for opened.
status=[]
#To store list of student who open or close each door.
door=[]

for d in range(1,1001):
 #Initially status of all door is closed.
 status.append(1)
 #Initially none of student open or closed the door.
 door.append(())
for student in range(1,101):
 k=student

 while(k<=1000):
  #change status of the door
  status[k-1] = -(status[k-1])
  #Add the student to the list
  door[k-1]=door[k-1]+(student,)
  # Find multiplication of student's number
  k +=student
#To count opened door after passing allstudent
count=0
ans = open("door.txt","w")
for d in range(1,1001):
 if(status[d-1] == -1):
  #Filter the open doors
  #Increase count of open door by 1
  count +=1
  #Print the door number and students who open or closed the door.
  print >>ans,d,door[d-1]
#print the total number of open doors
print count