need help urgently!!!

the question says :
The C++ programming course has 250 students. As each students needs his/her
heavy textbook in class and lab, lockers are to be assigned to students; one
locker for each student. Before assigning the lockers, the course instructors sort
all students names in one list and play the following game: they ask the first
student on the list to go and open all lockers. They then ask the 2nd student to go
and close all the even‐numbered lockers. The 3rd student is asked to check every
3rd locker. If it is open, the student closes it; if it is closed, the student opens it.
The 4th student is asked to check every 4th locker. If it is open, the student closes
it; if it is closed, the student opens it. The remaining students continue this
game. In general the nth student checks every nth locker. If th elocker is open, the
student closes it; if it is closed, the student opens it. After all the students have
taken their turns, some of the lockers are open and some are closed. Write a
program that prompts the user to enter the number of lockers. After the game is
over, the program outputs the number of lockers that are opened. Test run your
program for the following inputs: 1000, 5000, and 10000.
Hint: Consider locker number 100. This locker is visited by student numbbers 1, 2,
4, 5, 10, 20, 25, 50 and 100. These are th epositive divisors of 100. Similarly,
locker 30 is visited by student numbers 1, 2, 3, 5, 6, 10, and 30. Notic ethat if th
enumber of positive divisors of a locker number is odd then at th eend of the
game this locker is opened. If the number of positive divisors of a locker number
is even, then at th eend of the game, the locker is closed.

I am stuck how should I continue this qusetion? this is what I have done so far...



#include <iostream>
using namespace std;
int main()

{
int no;
int ctropen=0;
int ctr=0;

cout<<"Enter no. of lockers ";
cin>>no;

for (int i=1; i<=no ;i++)
{


for (int r=1;((r>=i) && (r<=250)) ;r++)
{
ctr=0;
if ( i % r == 0)
ctr++;

}

if (ctr % 2 != 0)

ctropen++;

}

cout<<"lockers opened : "<<ctropen<<endl;

system ("pause");
return 0;
}
If 0 =='open' and 1=='closed'
after 1st pass all locker doors are open so the array consists of all 0's
after 2nd pass every second door is closed so the array looks like 0,1,0,1,0,1 etc
after 3rd pass every 3rd door will be opened or shut so array looks like 0,1,1,1,0,0 etc
Use the epositive numbers to abbreviate the code.
Topic archived. No new replies allowed.