A HOTEL with 1000 rooms has 1000 waiters. Each waiter and room is given a number from 1-1000.
Initially, waiter with number 1 goes and closes doors of all rooms.
After that waiter with number 2 goes and changes the state of doors corresponding to multiples of that 2.
After that waiter number 3 goes and changes the state of doors corresponding to multiples of 3.
So on and so forth
Find the number of doors that are open after the 1000th waiter has returned .
NOTE: Changes the state of door means that opened doors are closed and closed doors are opened.
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.
Only the room numbers which are perfect square will be left close! There are 31 perfect squares (natural numbers) less than 1000. Hence, 1000 - 31 = 969 will be left open.
Detailed explanation: A room is left close if number of its divisors (including 1 and the number itself) is odd. For example, take room no. 4: Divisors - 1 ( -> close), 2 ( -> open), 4 ( ->close). Hence, finally close.
Now a natural number n can be written in the form of
n = p a ∗ q b ∗ r c . . . .
where, p , q , r , . . . are prime factors of n and a , b , c , . . . are natural numbers.
Number of divisors,
D ( n ) = ( a + 1 ) ( b + 1 ) ( c + 1 ) . . . . .
D ( n ) can be odd only if each of a , b , c , . . . is even. This in turn implies that number n is a perfect square.