输出所有小于等于n(n为一个大于2的正整数)的素数,

输出所有小于等于n(n为一个大于2的正整数)的素数,
如题
zhhua_tang 1年前 已收到1个回答 举报

cbouamyd 春芽

共回答了15个问题采纳率:80% 举报

var
a:array[1..100000] of boolean;
n,i:longint;
begin
fillchar(a,sizeof(a),false);
a[2]:=true;
readln(n);
for i:=2 to n do
if a[i] then
begin
writeln(i);
for j:=2 to n div i do a[i*j]:=false;
end;
end.
筛选法找素数.

1年前

2
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.530 s. - webmaster@yulucn.com