有没有谁懂Pascal语言的,求帮助!

2025-05-16 19:49:37
推荐回答(3个)
回答(1):

var a,b,i,yu1,yu2:integer;

function iszhishu(m:integer):boolean;  //判断是否是质数的函数
  var k,i:integer;
  
  begin
    k:=trunc(sqrt(m)); //除数的上限
    i:=2;              //除数的起点
    iszhishu:=true;  //默认为质数
    if m<=1 then iszhishu:=false;  //小于等于1的都不是质数
    while (m>1) and (i<=k) do  //开始在指定区间内做除法进行判断
      begin
         if (m mod i)=0 then iszhishu:=false;  //有整除情形出现就不是质数
         inc(i); //除数加1
      end; 
  end;

begin
   readln(a,b);
   yu1:=0;yu2:=0;
   for i:=a to b do
       begin
         if iszhishu(i) then 
            begin
               if (i mod 4)=1 then inc(yu1);
               if (i mod 4)=3 then inc(yu2);
            end;
       end;
   writeln('yu1:',yu1);
   writeln('yu2:',yu2);
   writeln;
end.

除以4余1的有:13 17 29 37

除以4余3的有:11 19 23 31 

回答(2):

var
total,ans,i,n,m:longint;
function pd(x:longint):boolean;
var k,i:longint;
begin
k:=2; i:=x; pd:=false;
while (k<=trunc(sqrt(i))) and (i mod k<>0) do inc(k);
if k>trunc(sqrt(i)) then pd:=true;
end;
begin
readln(n,m);
for i:=n to m do begin
if (pd(i))and(i mod 4=1) then inc(total)
else if (pd(i))and(i mod 4=3) then inc(ans);
end;
writeln('di yi lei :',total);
writeln('di er lei :',ans);
end.

回答(3):