PROGRAM lamps
  IMPLICIT NONE
  
  INTEGER :: n, diadromi, k
  LOGICAL, ALLOCATABLE :: lamp(:) ! on or off => Logical
  
  DO 
     PRINT *, "Dose plhthos lampwn"
     READ *, n
     IF (n > 0) EXIT
     PRINT *, "Den edoses thetiko arithmo"
  END DO

  ALLOCATE(lamp(n))

  lamp = .TRUE.  ! oles anammenes

  DO diadromi = 1,SIZE(lamp)
     DO k = 1,SIZE(lamp)
        IF (MOD(k, diadromi)==0) THEN
           lamp(k) = .NOT.lamp(k) ! allazei katastash
        END IF
     END DO
  END DO

  PRINT *, COUNT(lamp)  ! metra poses einai anammenes (true)

END PROGRAM lamps
