PROGRAM perfect
  IMPLICIT NONE

  INTEGER :: n, s, i

  DO
     PRINT *, "Dose thetiko akeraio"
     READ *, n
     IF (n > 0) EXIT
  END DO

  s = 0
  DO i = 1,n ! o n den exei diairetes panw apo n
     IF (MOD(n,i) == 0) s = s + i !!! to i einai diairetis tou n
  END DO

  IF (s == 2*n) THEN 
     PRINT *, " O ", n, "einai teleios"
  ELSE
     PRINT *, " O ", n, "den einai teleios"
  END IF

END PROGRAM perfect
