var
a,b,x:longint;
begin
while not seekeof do begin
x:=0;
readln(a);
for b:=2 to a-1 do
begin
if a mod b=0 then x:=1;
end;
if a<=1 then x:=1;
case x of
0:writeln('質數');
1:writeln('非質數');
end;
end;
end.
----------
以上用了大量mod,可能超時
有什麽簡便方法?
var
a,b,x:longint;
begin
while not seekeof do begin
x:=0;
readln(a);
for b:=2 to a-1 do
begin
if a mod b=0 then x:=1;
end;
if a<=1 then x:=1;
case x of
0:writeln('質數');
1:writeln('非質數');
end;
end;
end.
----------
以上用了大量mod,可能超時
有什麽簡便方法?