显然质数是指不能被1和自己以外的数整除的数
for i:=2 to trunc(sqrt(n)) do
if n mod i=0 then exit(false);
exit(true);
楼主可以自己想想为什么sqrt就可以了
program ui (input,output);
var
a,i:longint;
begin
readln(a);
if a=1 then begin writeln('NO');exit;end;
for i:=2 to trunc(sqrt(a)) do
if a mod i=0 then begin writeln('NO');exit;end;
writeln('yes');
end.
var
n,i : qword;
begin
readln(n);
for i := 2 to n div 2 do
if n mod i = 0 then break;
if n div 2 = i then write('YES')
else write('NO');
end.
function pan(j:longint):boolean;
var i,f:longint;
begin
f;=-1;
for i:=1 to j div 2 do
if j mod =0 then f:=0;
if f=0 then exit(false)
else exite(true);
end;
百度一下,你就知道·~~
很多的·~~~~这些语言类的题目~~