Answer:
Locker 1,4,9,16,25,36,49,64,81,100 ( Perfect squared lockers)
Step-by-step explanation:
Each locker whose number is a perfect square will be open. Each locker has two possible states, open or closed. let us assume 0 means closed and 1 means open.
A locker is initally closed, and it will only be open if we change its state an odd number of times. That is, if a locker has initial state 0, changing its state once time would make it 1(open). Changing its state 3 times i.e.
0->1
1->0
0->1
Would make it open.
Each locker is opened by a number that is the factor of that locker number. A factor can be defined as:
A number c will be a factor of number a if c multiplied by a number b is a.
i.e. c*b = a. This means b is also a factor of a.
Each locker number that is a perfect square will only be changed an odd number of times, this is because perfect squares have only odd number of factors, where are other numbers have even number of factors.
for example, 16 is a perfect square of 4. Its factors are
1x16, 2x8, 4x4 but when considering factors, we only count each factor once, therefore if a number occurs twice, it is still counted as once. hence, there are a total of only 5 factors of 16, namely 1,2,4,8,16
locker 16 is closed initially,
Student 1 opens the locker.
Student 2 closes the locker.
Student 4 opens the locker.
Student 8 closes the locker.
Student 16 opens the locker.
locker 8 will be changed by students 1,2,4,8, which will not change its state.
locker 8 is closed initially.
student 1 will open the locker
student 2 will close the locker
student 4 will open the locker
student 8 will close the locker.
Hence all the lockers that are perfectly squared will be open.
Python Code:
lockers = [] #Locker numbers
lockers_s = [] #Locker states False means close, True means open.
for i in range(1, 101):
lockers.append(i)# initialize locker numbers
lockers_s.append(False) #set all locker states to closed.
for i in range(0, 100):
for j in range(0, 100):
if i == 0: # Student 1. Opening all the lockers
lockers_s[j] = True
elif i == 1:
if lockers[j] % 2 == 0: # Student 2, closing all the lockers that are multiples of 2.
lockers_s[ lockers[j]-1 ] = False
else:
if lockers[j] % (i+1) == 0: #if the locker number is a multiple of student number (i+1)
lockers_s[ lockers[j]-1 ] = not lockers_s[ lockers[j]-1 ] # Change states.
for i in range(0, 100):
if lockers_s[i]:
print(i+1, end=',') #print all the open lockers.