jay2054
Answered

There is a school with 1,000 students and 1,000 lockers. On the first day of term the headteacher asks the first student to go along and open every single locker, he asks the second to go to every second locker and close it, the third to go to every third locker and close it if it is open or open it if it is closed, the fourth to go to the fourth locker and so on. The process is completed with the thousandth student. How many lockers are open at the end?

Answer :

As many were opened during the time period. Jk, I don't know. This is a hard one
caylus
Hello,

answer: 31

I have make a programm in Qbasic

CONST Faux = 0
CONST Vrai = NOT (Faux)
CONST nb = 1000
DIM SHARED locker(nb) AS INTEGER
DIM i AS INTEGER, j AS INTEGER, answer AS INTEGER
'1 first student
FOR i = 1 TO nb: locker(i) = Vrai: NEXT i: ' CALL See
'2 2nd student
FOR i = 2 TO nb STEP 2: locker(i) = Faux: NEXT i: 'CALL See
FOR j = 3 TO nb
    FOR i = j TO nb STEP j
        locker(i) = NOT (locker(i))
    NEXT i
    'CALL See
NEXT j
answer = 0
FOR i = 1 TO nb
    IF locker(i) THEN answer = answer + 1
NEXT i
PRINT "answer="; answer
END

SUB See

SHARED locker() AS INTEGER
DIM i AS INTEGER
locker(0) = 0
FOR i = 1 TO nb
    PRINT locker(i);
    IF locker(i) THEN locker(0) = locker(0) + 1
NEXT i
PRINT locker(0)

END SUB


Other Questions