pascalabcnet/InstallerSamples/Algorithms/Eratosthenes.pas
Бондарев Иван e6e67c193c initial commit
2015-05-14 21:35:07 +02:00

27 lines
444 B
ObjectPascal

// "Ðåøåòî Ýðàòîñôåíà" - âû÷èñëåíèå ïðîñòûõ ÷èñåë
const n = 100000;
var primes: set of integer;
begin
primes := [2..n];
for var i:=2 to round(sqrt(n)) do
begin
if not (i in primes) then
continue;
var x := i*i;
while x<=n do
begin
Exclude(primes,x);
x += i;
end;
end;
writeln('Ïðîñòûå ÷èñëà < ',n,':');
writeln(primes);
writeln;
writeln('Âðåìÿ âû÷èñëåíèÿ: ',Milliseconds/1000);
end.