unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
primes:TStringList;
nr:Integer;
i,j,n, luckynr: Integer;
begin
primes:= TStringList.Create;
nr:= strtoint(edit1.Text);
for i:= 2 to nr do begin
primes.Add(inttostr(i));
end;
//showmessage(primes[-1]);
i:=0;
n:= i+1;
while True do begin
j := strtoint(primes[n]);
luckynr:=strtoint(primes[i]);
if j = strtoint(primes[primes.count-1]) then begin
if j mod luckynr = 0 then begin
primes.Delete(primes.IndexOf(inttostr(j)));
end;
i:=i+1;
n:=i+1;
end
else if j mod luckynr = 0 then begin
primes.Delete(primes.IndexOf(inttostr(j)));
n:=n+1
end
else if luckynr = strtoint(primes[primes.count-1]) then begin
break;
end
else begin
n:=n+1;
end;
end;
end;
end.