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-
After the recent Puzzlefry annual marathon, the judges were comparing notes to determine who finished where. From their notes, can you help them to reconstruct the final result?
Matthew Merryman beat Tom Trent and Jimmy James. Peter Piper beat Jimmy James, Tom Trent and Alan Ardman. ...Read More »Palindrome dates
This year on October 2, 2001, the date in MMDDYYYY format will be a palindrome (same forwards as backwards). 10/02/2001 ...Read More »The Bacteriologist
A scientist is experimenting with bacteria that are one micron in diameter and that reproduce by dividing every minute into ...Read More »I sit between you and a star riddle
I sit between you and a star, but far below me is an empty space. I can be infinite or ...Read More »Sword Play
The local king, determined to defend his kingdom from that wicked ogre, sent his two eldest sons to the court ...Read More »Turn again
It turns around once, what is out will not get in. It turns around again, what is in will not ...Read More »Making Handkerchief
I have 50 feet long of cloth, I need to create 50 handkerchiefs each size of 1 foot. I take ...Read More »What’s The Missing Number?
Time measurement
There are two sand timers which can show 7 minutes and 4 minutes respectively. Measure time of 9 minutes using ...Read More »Can you find the killer?
Sherlock holmes is called upon on a crime scene. A woman has been killed and there are only three suspects ...Read More »Number Series Pattern
If, 6 / 7 = 2 3 / 9 = 7 8 / 2 = 6 Then 4 / 5 ...Read More »What did the wise man say to them?
An Arab sheikh tells his two sons to race their camels to a distant city to see who will inherit ...Read More »Lock & Key Riddle
You want to send a valuable object to a friend. You have a box which is more than large enough ...Read More »Less you see
The more of this there is, the less you see. What is it?Read More »Small room to Big room lateral thinking puzzle
Jim entered in a small room. Door Closed When the door opened, Jim is in a big room. How that’s ...Read More »Right Wrong word puzzle
Which word, if pronounced right, is wrong, but if pronounced wrong is right?Read More »A basketball riddle
A man takes a basketball and throws it as hard as he can. There is nothing in front, behind, or ...Read More »Count the Animals
A cricket has 6 legs, a squirrel has 4 legs and a spider has 8 legs. In a local zoo, ...Read More »Are You Intelligent ?
What do you see in the given picture?Read More »Can you find the circumference of each wheel?
A friend of mine in Bangalore owns a horse-driven carriage. It was found that the fore wheels of the carriage ...Read More »