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-
Travel but stays in home
I like to roam but I’ll always stay home, He likes to travel but stays in home, He leaves a ...Read More »4 Weight bars to weigh given wieght puzzle
You have to take 4 weight bars (all of integer values). Using only those 4 bars you can weight all ...Read More »Driving car riddle
You are driving a car at full speed. Suddenly you see a little boy, an old woman and a traffic ...Read More »Coin Toss investigation puzzle
A dead body is found at the bottom of a multi-storey building. Seeing the position of the body, it is ...Read More »Make Maths Equation
Use the digits 1, 2, 3, 4, 5 and 6 once only, in this multiplication sum to make it correct. ...Read More »Three hat colors Microsoft Puzzle
A team of three people decide on a strategy for playing the following game. Each player walks into a room. ...Read More »Average speed of train riddle
A train is going at a speed of 60kmph towards Delhi and returned back at a speed of 30kmph. What ...Read More »Shouts along the street
It shouts along the street, has not any lungs. It tugs at leaves and hurls them at people, old and ...Read More »Fashion that never change
Fashions change but what can a person wear that is never out of style?Read More »Circular Cake
How is it possible to cut a traditional circular cake into 8 equal size pieces, with only 3 cuts?Read More »Who is taller A or B?
500 men are arranged in an array of 10 rows and 50 columns according to their heights. Tallest among each ...Read More »Rebus Picture Riddle
What does this rebus picture mean?Read More »Has legs but does not walk
What has two legs but does not walk?Read More »Minimum number of persons needed to cross a Desert
In the middle of the confounded desert, there is the lost city of “Ash”. To reach it, you will have ...Read More »All in One Riddle
Gaze at this sentence for just about thirty seconds and then explain what makes it quite different from the average ...Read More »Watermelon in the sun math riddle
There is a 100 pound watermelon laying out in the sun. 89 percent of the watermelon’s weight is water. After ...Read More »Colour test
First, think of the color of the clouds. Next, think of the color of snow. Now, think of the color ...Read More »Rich man’s and gold Coin puzzle
A rich man died. In his will, he has divided his gold coins among his 5 sons, 5 daughters and ...Read More »Word to Number
What number does the below three word/phrase identify and why? 1. Deck 2. Year 3. Singing in the RainRead More »Dice numbering puzzle
James is having 2 dices. Dice 1- is a normal dice numbered 1 to 6. Dice 2- is also having ...Read More »