先给你说一个 判断素数的函数:
=============================================================
function judge(num:longint):boolean;
var
i:longint;
begin
for i:=2 to trunc(sqrt(num)) do//从2到所判断数的算术跟
begin
if num mod i=0
then exit(false);//不是素数
end;
exit(true);//是素数
end;
=============================================================
求第一百个素数的代码如下:
=============================================================
program t;
const
maxn=10000000;
var
i,j,k,total:longint;
a:array[1..maxn]of longint;
function judge(num:longint):boolean;
var
i:longint;
begin
for i:=2 to trunc(sqrt(num)) do//从2到所判断数的算术跟
begin
if num mod i=0
then exit(false);//不是素数
end;
exit(true);//是素数
end;
begin
for i:=1000 to 2000 do
begin
if judge(i)
then begin
inc(total);
a[total]:=i;
end;
end;
writeln(a[100]);
end.
=============================================================
答案是1721
希望对你有所帮助
素数