FUNCTION NG_TO(X:INTEGER):BOOLEAN;
VAR J: INTEGER;
    KT: BOOLEAN;
BEGIN
     KT:= TRUE;
     IF X = 1 THEN KT:= FALSE
     ELSE
         FOR J:= 2 TO X DIV 2 DO
             IF X MOD J = 0 THEN KT:= FALSE;
     NG_TO:= KT;
END;
FUNCTION DAO_SO(Y: INTEGER): INTEGER;
VAR S:INTEGER;
BEGIN
     S:=0;
     WHILE Y<>0 DO
     BEGIN
          S:=S*10 + (Y MOD 10);
          Y:= Y DIV 10;
     END;
     DAO_SO:=S;
END;
VAR X,Y,P,Q,I:INTEGER;
    F,F1: TEXT;
BEGIN
     ASSIGN(F,'BAI4.INP'); RESET(F);
     ASSIGN(F1,'BAI4.OUT');REWRITE(F1);
     WRITE(F1,'CAC SO CAN TIM');WRITELN(F1);
     READ(F,P,Q);
     FOR I:= P TO Q DO
         IF NG_TO(DAO_SO(I))=TRUE THEN WRITELN(F1,I:3);
     CLOSE(F);
     CLOSE(F1);
END.








