procedure TForm1.Edit1Change(Sender: TObject);
var
a, b, c, s, d: Integer;
begin
s := 1;
Caption := '';
if (TryStrToInt(Edit4.Text, d) and TryStrToInt(Edit1.Text, a) and
TryStrToInt(Edit2.Text, b) and TryStrToInt(Edit3.Text, c)) then
begin
while (a) and (a <> c) do
begin
if a mod d = 0 then
s := s * a;
inc(a);
end;
Caption := FloatToStr(s);
end;
end;