Monkey and Lamp Puzzle
A very big building in which thousand monkeys are living is lighted by thousand lamps. Every lamp is connected to a unique on/off switch, which are numbered from 1 to 1000. At some moment, all lamps are switched off. But because it is becoming darker, the monkeys would like to switch on the lights. They will do this in the following way.
Monkey 1 presses all switches that are a multiple of 1.
Monkey 2 presses all switches that are a multiple of 2.
Monkey 3 presses all switches that are a multiple of 3.
Monkey 4 presses all switches that are a multiple of 4.
Etc., etc.
How many lamps are switched on after monkey 1000 pressed his switches?
And
which lamps are switched on?
Only the lights connected to switches with a number that has an odd number of factors are left on. These are the square numbers. The largest square square number less than 1000 is 31^2 = 961, so there are 31 lights on connected to the switches 1^2, 2^2, … 31^2.
/*
Yep Thats Perfect!
Following is a java program to do the same thing.
*/
class k1{
public static int[] factorize (int a[], int p)
{
int count=0,no=p;
int b[]= new int[a.length];
b=a;
for(int i=2;i<=p;i++)
if(p%i==0){b[count++]=i;}
b[count++]=1;
return b;
}
public static int no_of_factors(int b[])
{
int counter=0;
for(int i=0;i<b.length-1;i++)
{
if(b[i+1]!=b[i]&&b[i]!=0) counter++;
}
return counter;
}
public static void main(String args[])
{
int on_count=0;
int a[]= new int[50];
for(int i=1;i<=1000;i++)
{
factorize(a,i);
int x = no_of_factors(a);
if(x%2!=0) on_count++;
for(int j=0;j<50;j++)a[j]=0;
}
System.out.print(on_count);
}// end of main
}// end of class
Your Answer
More puzzles to try-
Make it 24
Can you make numbers like 24, using numbers 3,3,7 & 7 with any arithmetic operator?Read More »Magic Algebra Fun
You are given with the following sum. Each of the letters can be decoded as a digit. If we tell ...Read More »Find the next in series
Find the last number in the series below: voN luJ yaM raM —Read More »Why would a hair stylist rather cut the hair of two brunettes than one red head?
Why would a hair stylist rather cut the hair of two brunettes than one red head?Read More »Long & Short
Arnold Schwarzenegger’s is really long. Michael J. Fox’s is short. Daffy Duck’s isn’t human. Madonna doesn’t have one. What is ...Read More »Alphametic BaseBall
Replace the letters of words with a number so that the below equation holds true BASE + BALL ——— GAMES ...Read More »Man became millionaire after rice trade puzzle
A man buys rice at $1 a pound from American growers and sells them at $0.05 a pound in Africa. ...Read More »FIND THE MISSING AMOUNT
Three men in a cafe order a meal the total cost of which is $15. They each contribute $5. The ...Read More »Five Friends Surnames Puzzle
Five friends with surname Batliwala, Pocketwala, Talawala, Chunawala and Natakwala have their first name and middle name as follow- 1. Four ...Read More »Dog crossed the river riddle
A man stands on one side of a river, his dog on the other. The man calls his dog, who ...Read More »Digit sums of multiples of 11
Some multiples of 11 have an even digit sum. For example- 7*11 = 77 and 7+7 = 14, which is ...Read More »Always in you riddle
Always in you, Sometimes on you; If I surround you, I can kill you. What am I ?Read More »Pick the fresh Egg
A container contains 100 eggs. They can be either fresh or rotten. What is sure is the fact that there ...Read More »Measure 9 minutes from 2 hourglasses puzzle
Using only a Four-minute hourglass and a seven-minute hourglass, How will you measure exactly nine minutes? Restriction:- Without the process ...Read More »Common Meaning
What do an Island and the letter T have in common?Read More »missing word puzzle
My wonderful Puzzlefry printer has made a pig’s ear out of my latest puzzle. In each sentence below, one letter ...Read More »Find the next number
Find next number in sequence 81 87 69 82 84 ? Hint – Information Interchange code By America is a must ...Read More »Board Setting Puzzle
As you can see in the picture, you have a hole with dimensions 9 ft x 2 ft Also available ...Read More »Closed Room Riddle
You are in a room that is completely bricked in on all four sides, including the ceiling and floor. You ...Read More »Measure the Time
The measurement of time, That can’t be found on a clock, But can be looked upon on a map. Who ...Read More »