IDENTIFICATION DIVISION.
PROGRAM-ID. 102C.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP   PIC X(15).
01 N     PIC 9(6).
01 K     PIC 9(6).
01 S     PIC 9(5).
01 A     PIC 9(1).
01 S1    PIC 9(5)V9.
01 S1-R  REDEFINES S1.
   03 F1 PIC 9(5).
   03 S2 PIC 9(1).
01 CNT   PIC 9(18).
01 OUT   PIC Z(17)9.
*>
PROCEDURE DIVISION.
  ACCEPT INP. 
  UNSTRING INP DELIMITED BY ' '
      INTO N K.
*>
  DIVIDE K BY 2 GIVING S REMAINDER A.
  DIVIDE N BY K GIVING S1.
*>
display 's1,a,f1=' s1 ' ' a ' ' f1
  IF (A = 1)
    COMPUTE CNT = F1 ** 3
  ELSE
    COMPUTE CNT = F1 ** 3
    IF (S2 < 5)
      COMPUTE CNT = CNT + F1 ** 3
    ELSE
      COMPUTE CNT = CNT + (F1 + 1) ** 3
    END-IF
  END-IF.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
 