问题:
There are 100 closed lockers in a hallway. A man begins by opening all the 100 lockers. Next, he closes every second locker. Then he goes to every third locker and closes it if it is open or opens it if it is closed (e.g., he toggles every third locker). After his 100th pass in the hallway, in which he toggles only locker number 100, how many lockers are open?
分析:
对于编号是 N 的箱子,它会在哪几轮被开或者关呢?这是问题的关键点之一。答案是当N可以被X轮整除的时候。比如,如果箱子号码是 10,那么,在第 1, 2, 5, 10 轮的时候,箱子会被开或者被关。
问题二:那么到底箱子最终是关着还是开着由什么决定呢?答案是当所有能够被整除的 轮数 是奇数的时候才是开着的的。比如箱子号码是16的时候,第一轮打开,第二轮关闭,第四轮打开,第八轮关闭,第十六轮打开。所以最后箱子是开着的的。 而这类号码都是开根号后为整数的。比如1, 4, 9, 16, 25, 36, 49, 64,81,100. 所以,最后总的开着的箱子的个数是10个。