logicmathThere are 1 million closed school lockers in a row, labeled 1 through 1,000,000.
You first go through and flip every locker open.
Then you go through and flip every other locker (locker 2, 4, 6, etc...). When you're done, all the even-numbered lockers are closed.
You then go through and flip every third locker (3, 6, 9, etc...). "Flipping" mean you open it if it's closed, and close it if it's open. For example, as you go through this time, you close locker 3 (because it was still open after the previous run through), but you open locker 6, since you had closed it in the previous run through.
Then you go through and flip every fourth locker (4, 8, 12, etc...), then every fifth locker (5, 10, 15, etc...), then every sixth locker (6, 12, 18, etc...) and so on. At the end, you're going through and flipping every 999,998th locker (which is just locker 999,998), then every 999,999th locker (which is just locker 999,999), and finally, every 1,000,000th locker (which is just locker 1,000,000).
At the end of this, is locker 1,000,000 open or closed?

Locker 1,000,000 will be open.
If you think about it, the number of times that each locker is flipped is equal to the number of factors it has. For example, locker 12 has factors 1, 2, 3, 4, 6, and 12, and will thus be flipped 6 times (it will end be flipped when you flip every one, every 2nd, every 3rd, every 4th, every 6th, and every 12th locker). It will end up closed, since flipping an even number of times will return it to its starting position. You can see that if a locker number has an even number of factors, it will end up closed. If it has an odd number of factors, it will end up open.
As it turns out, the only types of numbers that have an odd number of factors are squares. This is because factors come in pairs, and for squares, one of those pairs is the square root, which is duplicated and thus doesn't count twice as a factor. For example, 12's factors are 1 x 12, 2 x 6, and 3 x 4 (6 total factors). On the other hand, 16's factors are 1 x 16, 2 x 8, and 4 x 4 (5 total factors).
So lockers 1, 4, 9, 16, 25, etc... will all be open. Since 1,000,000 is a square number (1000 x 1000), it will be open as well.

## Similar riddles

See also best riddles or new riddles.

logicmathYou have been given the task of transporting 3,000 apples 1,000 miles from Appleland to Bananaville. Your truck can carry 1,000 apples at a time. Every time you travel a mile towards Bananaville you must pay a tax of 1 apple but you pay nothing when going in the other direction (towards Appleland). What is highest number of apples you can get to Bananaville?

833 apples.
Step one: First you want to make 3 trips of 1,000 apples 333 miles. You will be left with 2,001 apples and 667 miles to go.
Step two: Next you want to take 2 trips of 1,000 apples 500 miles. You will be left with 1,000 apples and 167 miles to go (you have to leave an apple behind).
Step three: Finally, you travel the last 167 miles with one load of 1,000 apples and are left with 833 apples in Bananaville.

logicmathThe owner of a banana plantation has a camel. He wants to transport his 3000 bananas to the market, which is located after the desert. The distance between his banana plantation and the market is about 1000 kilometer. So he decided to take his camel to carry the bananas. The camel can carry at the maximum of 1000 bananas at a time, and it eats one banana for every kilometer it travels.
What is the most bananas you can bring over to your destination?

First of all, the brute-force approach does not work. If the Camel starts by picking up the 1000 bananas and try to reach point B, then he will eat up all the 1000 bananas on the way and there will be no bananas left for him to return to point A.
So we have to take an approach that the Camel drops the bananas in between and then returns to point A to pick up bananas again.
Since there are 3000 bananas and the Camel can only carry 1000 bananas, he will have to make 3 trips to carry them all to any point in between.
When bananas are reduced to 2000 then the Camel can shift them to another point in 2 trips and when the number of bananas left are <= 1000, then he should not return and only move forward.
In the first part, P1, to shift the bananas by 1Km, the Camel will have to
Move forward with 1000 bananas – Will eat up 1 banana in the way forward
Leave 998 banana after 1 km and return with 1 banana – will eat up 1 banana in the way back
Pick up the next 1000 bananas and move forward – Will eat up 1 banana in the way forward
Leave 998 banana after 1 km and return with 1 banana – will eat up 1 banana in the way back
Will carry the last 1000 bananas from point a and move forward – will eat up 1 banana
Note: After point 5 the Camel does not need to return to point A again.
So to shift 3000 bananas by 1km, the Camel will eat up 5 bananas.
After moving to 200 km the Camel would have eaten up 1000 bananas and is now left with 2000 bananas.
Now in the Part P2, the Camel needs to do the following to shift the Bananas by 1km.
Move forward with 1000 bananas – Will eat up 1 banana in the way forward
Leave 998 banana after 1 km and return with 1 banana – will eat up this 1 banana in the way back
Pick up the next 1000 bananas and move forward – Will eat up 1 banana in the way forward
Note: After point 3 the Camel does not need to return to the starting point of P2.
So to shift 2000 bananas by 1km, the Camel will eat up 3 bananas.
After moving to 333 km the camel would have eaten up 1000 bananas and is now left with the last 1000 bananas.
The Camel will actually be able to cover 333.33 km, I have ignored the decimal part because it will not make a difference in this example.
Hence the length of part P2 is 333 Km.
Now, for the last part, P3, the Camel only has to move forward. He has already covered 533 (200+333) out of 1000 km in Parts P1 & P2. Now he has to cover only 467 km and he has 1000 bananas.
He will eat up 467 bananas on the way forward, and at point B the Camel will be left with only 533 Bananas.

logicmathHow to measure exactly 4 gallon of water from 3 gallon and 5 gallon jars, given, you have unlimited water supply from a running tap.

Step 1. Fill 3 gallon jar with water. ( 5p – 0, 3p – 3)
Step 2. Pour all its water into 5 gallon jar. (5p – 3, 3p – 0)
Step 3. Fill 3 gallon jar again. ( 5p – 3, 3p – 3)
Step 4. Pour its water into 5 gallon jar untill it is full. Now you will have exactly 1 gallon water remaining in 3 gallon jar. (5p – 5, 3p – 1)
Step 5. Empty 5 gallon jar, pour 1 gallon water from 3 gallon jar into it. Now 5 gallon jar has exactly 1 gallon of water. (5p – 1, 3p – 0)
Step 6. Fill 3 gallon jar again and pour all its water into 5 gallon jar, thus 5 gallon jar will have exactly 4 gallon of water. (5p – 4, 3p – 0)
We are done !

logicmathshortIf you're 8 feet away from a door and with each move you advance half the distance to the door. How many moves will it take to reach the door?

You will never reach the door! If you only move half the distance, then you will always have half the distance remaining no matter, how small is the number.

logicmathYou are standing in a pitch-dark room. A friend walks up and hands you a normal deck of 52 cards. He tells you that 13 of the 52 cards are face-up, the rest are face-down. These face-up cards are distributed randomly throughout the deck.
Your task is to split up the deck into two piles, using all the cards, such that each pile has the same number of face-up cards. The room is pitch-dark, so you can't see the deck as you do this.
How can you accomplish this seemingly impossible task?

Take the first 13 cards off the top of the deck and flip them over. This is the first pile. The second pile is just the remaining 39 cards as they started.
This works because if there are N face-up cards in within the first 13 cards, then there will be (13 - N) face up cards in the remaining 39 cards. When you flip those first 13 cards, N of which are face-up, there will now be N cards face-down, and therefore (13 - N) cards face-up, which, as stated, is the same number of face-up cards in the second pile.

funnylogicmathshortWhat do you get if you add 2 to 200 four times?

202 , 202 , 202 , 202.

logicmathshortI know a number which is spelled in an alphabetical order. Do you?

Forty.

funnylogicmathAn infinite number of mathematicians are standing behind a bar. The first asks the barman for half a pint of beer, the second for a quarter pint, the third an eighth, and so on. How many pints of beer will the barman need to fulfill all mathematicians' wishes?

Just one.

logicmathA witch owns a field containing many gold mines. She hires one man at a time to mine this gold for her. She promises 10% of what a man mines in a day, and he gives her the rest. Because she is blind, she has three magic bags who can talk. They report how much gold they held each day, and this is how she finds out if men are cheating her. Upon getting the job, each man agrees that if he isn't honest, then he will be turned into stone. So around the witch's mines, many statues lay!
Now comes an honest man named Garry. He accepts the job gladly. The witch, who didn't trust him said, "If I wrongly accuse you of cheating me, then I'll be turned into stone."
That night, Garry, having honestly done his first day's job, overheard the bags talking to the witch. He then formulated a plan... The next night, he submitted his gold, and kept 1.6 pounds of gold. Later, the witch talked with her bags. The first bag said it held 16 pounds that day. The second one said it held 5 pounds. The third one said it held 2 pounds. Beaming, the witch confronted Garry. "You scoundrel, you think you could fool me. Now you shall turn into stone!" the witch cried. One second later, the witch was hard as a rock, and very grey-looking. How did Garry brilliantly deceive the witch?

Garry put 2 lbs. in bag #1. 3 lbs. were put in bag #2. 11 lb. were put into bag #3. He then put bag #2 into bag #3, and bag #1 into bag #2. The bags only felt the weight of the gold above it. Thus they inadvertently gave the message that 23 lbs. were taken.

logicmathYou are visiting NYC when a man approaches you.
"Not counting bald people, I bet a hundred bucks that there are two people living in New York City with the same number of hairs on their heads," he tells you.
"I'll take that bet!" you say. You talk to the man for a minute, after which you realize you have lost the bet.
What did the man say to prove his case?

This is a classic example of the pigeonhole principle. The argument goes as follows: assume that every non-bald person in New York City has a different number of hairs on their head. Since there are about 9 million people living in NYC, let's say 8 million of them aren't bald.
So 8 million people need to have different numbers of hairs on their head. But on average, people only have about 100,000 hairs. So even if there was someone with 1 hair, someone with 2 hairs, someone with 3 hairs, and so on, all the way up to someone with 100,000 hairs, there are still 7,900,000 other people who all need different numbers of hairs on their heads, and furthermore, who all need MORE than 100,000 hairs on their head.
You can see that additionally, at least one person would need to have at least 8,000,000 hairs on their head, because there's no way to have 8,000,000 people all have different numbers of hairs between 1 and 7,999,999. But someone having 8,000,000 is an essential impossibility (as is even having 1,000,000 hairs), So there's no way this situation could be the case, where everyone has a different number of hairs. Which means that at least two people have the same number of hairs.