A number theory problem by A Former Brilliant Member

Suppose you're in a hallway lined with 100 closed lockers. You begin by opening every locker. Then you close every second locker. Then you go to every third locker and open it (if it's closed) or close it (if it's open). Let's call this action toggling a locker. Continue toggling every nth locker on pass number n. After 100 passes, where you toggle only locker #100, how many lockers are left open?


The answer is 10.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

Miki Moningkai
Feb 21, 2015

10 lockers are left open: Lockers #1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

Each of these numbers are perfect squares. This problem is based on the factors of the locker number.

Each locker is toggled by each factor; for example, locker #40 is toggled on pass number 1, 2, 4, 5, 8, 10, 20, and 40. That's eight toggles: open-closed-open-closed-open-closed-open...

The only way a locker could be left open is if it is toggled an odd number of times. The only numbers with an odd number of factors are the perfect squares. Thus, the perfect squares are left open.

Elliott Macneil
Mar 2, 2014

I found it easiest to make this problem smaller, for example 10 lockers.We end up having 3 open and 7 closed.This corresponds with the amount of square numbers that are contained in the amount of lockers.Seeing as 10^2 = 100, this means that there will be 10 lockers open and 90 closed. Q.E.D.

If you do a quick run through of the situation, you will realize that all even-factored numbers will remain closed. Why? Because for every person opening the door, there is an equal number of people closing it.

This narrows us down to the numbers which have only odd factors. Such numbers are all perfect squares, since one of their factors will be repeated (hence, a square).

There are 10 squares between 1 and 100.

Vaibhav Jain
Mar 8, 2014

python code for that:-

locked=1

open=0

a=[]

for i in range (0,101):

a.append(1)

for i in range (1,101):

for j in range (1,101):

    if (j%i):

        a[j]=a[j]^1

count=0

for i in range (1,101):

if(a[i]==0):

    count=count + 1

print "total number of doors left open is %d" %count

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...