IDENTIFICATION DIVISION.
PROGRAM-ID. 170D.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(1600000).
*>
WORKING-STORAGE SECTION.
01 N          PIC  9(06).
01 P1         PIC  9(07) COMP.
01 P2         PIC  9(07) COMP.
01 I          PIC  9(06) COMP.
01 J          PIC  9(06) COMP.
01 IDX        PIC  9(06) COMP.
01 TBL1.
   03 A       PIC  9(06) COMP OCCURS 200000 DEPENDING ON N.
01 TBL2.
   03 TBL-M   OCCURS 200000.
      05 B    PIC  9(07) COMP.
      05 C    PIC  9(01) COMP.
01 CNT        PIC  9(06).
01 OUT        PIC  Z(05)9.
*> 
PROCEDURE DIVISION.                          
  ACCEPT N.
*>
  OPEN INPUT STDIO.
  READ STDIO.
  CLOSE STDIO.
*>
*>MOVE ZERO TO TBL1 TBL2.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO A(I) IDX
    ADD  1               TO B(IDX)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  SORT A ASCENDING KEY A.
  MOVE 0 TO CNT.           
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    IF (C(A(I)) = 0)
      IF (B(A(I)) > 1)
        MOVE 1 TO C(A(I))
      END-IF
*>
      PERFORM VARYING J FROM 2 BY 1 UNTIL A(I) * J >  A(N)
        MOVE 1 TO C(A(I) * J)
      END-PERFORM
    END-IF
  END-PERFORM.
*>
  MOVE 0 TO CNT.           
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    IF (C(A(I)) = 0)
      ADD 1 TO CNT
    END-IF
  END-PERFORM.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
