unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  mas:array[1..1000] of integer;
  flag:byte;
  i,j,n,m,k:longint;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  label1.Caption:='2 3 5';
  mas[1]:=2;mas[2]:=3;mas[3]:=5;
  m:=3;Edit1.Text:='';
  k:=6;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then begin
    n:=strtoint(Edit1.Text);
    flag:=0;
    for i:=1 to m do begin
      if n/mas[i]=int(n/mas[i]) then flag:=1;
    end;
    if flag=0 then begin
      label1.Caption:=Label1.Caption+' '+inttostr(n);
      m:=m+1;
      k:=n+1;
      mas[m]:=n;
    end else ShowMessage(' Неправильно ');
    Edit1.Text:='';
   end;

end;

end.
