3. 1 .. N内的所有合数
3. 1 .. N内的所有合数
program ex_3;
var
a : array [2..10000] of boolean;
n, i, j, x : integer;
begin
readln(n);
for i := 2 to n do
a[i] := true;
x := 1;
repeat
x := x+1;
if a[x] then
begin
i := x;
while i < n do
begin
i := i+x;
a[i] := false;
end;
end;
until x*x > n;
j := 0;
for i := 2 to n do
if a[i] = false then
begin
j := j+1;
if j mod 10 <> 0 then
write(i, ' ')
else
writeln(i);
end;
readln;
end.
program ex_3;
var
a : array [2..10000] of boolean;
n, i, j, x : integer;
begin
readln(n);
for i := 2 to n do
a[i] := true;
x := 1;
repeat
x := x+1;
if a[x] then
begin
i := x;
while i < n do
begin
i := i+x;
a[i] := false;
end;
end;
until x*x > n;
j := 0;
for i := 2 to n do
if a[i] = false then
begin
j := j+1;
if j mod 10 <> 0 then
write(i, ' ')
else
writeln(i);
end;
readln;
end.


浙公网安备 33010602011771号