IDENTIFICATION DIVISION.
PROGRAM-ID. 162B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N          PIC  9(7) COMP.
01 I          PIC  9(7) COMP.
01 S          PIC  9(6) COMP.
01 A1         PIC  9(1).
01 A2         PIC  9(1).
01 GK         PIC  9(18) COMP.
01 OUT        PIC  Z(17)9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    DIVIDE I BY 3 GIVING S REMAINDER A1
    DIVIDE I BY 5 GIVING S REMAINDER A2
*>
    IF (A1 NOT = 0) AND (A2 NOT = 0)
      ADD I TO GK
    END-IF
  END-PERFORM.
*>
  MOVE GK TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
