Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program New;
- function IsPrime(var p: TIntegerArray; a: Integer): Boolean;
- var
- b: Integer;
- begin
- Result := False;
- for b := 0 to High(p) do
- if a mod p[b] = 0 then
- Exit;
- SetLength(p, High(p) + 2);
- p[High(p)] := a;
- Result := True;
- end;
- procedure MarkPrime(var n: array of Boolean; a: Integer);
- var
- b: Integer;
- begin
- for b := 1 to High(n) / a do
- if n[b * a] then
- n[b * a] := False;
- end;
- function ProducePrimes(t: Integer): Integer;
- var
- n: array of Boolean;
- p: TIntegerArray;
- i: Integer;
- begin
- Result := GetSystemTime;
- SetLength(n, t + 1);
- for i := 2 to t do
- n[i] := True;
- for i := 2 to t do
- if(IsPrime(p, i)) then
- MarkPrime(n, i);
- Result := GetSystemTime - Result;
- end;
- var
- i: Integer;
- begin
- Writeln('Begin');
- for i := 1 to 250 do
- Writeln(IntToStr(i * 100) + ': ' + IntToStr(ProducePrimes(i * 100)));
- Writeln('End');
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement