Problem

sddd1

Member
Joined
Jul 22, 2021
Messages
14
Programming Experience
1-3
There are 500 light bulbs (numbered 1 to 500) arranged in a row. Initially they are all OFF. Starting with bulb 2, all even numbered bulbs are turned ON. Next, starting with bulb 3, and visiting every third bulb, it is turned ON if it is OFF, and it is turned OFF if it is ON. This procedure is repeated for every fourth bulb, then every fifth bulb, and so on up to the 500th bulb. Write a java program to determine which bulbs are OFF at the end of above exercise.
 
First of all, this is a C# forum. Asking for a Java program could be a bit problematic.

Second, this forum is not a code writing service. We can help you with a specific problem that you may be encountering as you write your code, but we won't write your code for you.

Seems like the problem is simply implement:
But instead of looking at all the prime numbers, look at all the composite numbers less than 500.
 
Oh! I see, there is the extra wrinkle that some composite numbers which initially got turned off may later be turned back on.
 
Back
Top Bottom