大众信息网

pascal问题 怪

答案:2  mip版
解决时间 2021-08-13 19:20
  • 提问者网友:轉頭涐還是涐
  • 2021-08-13 09:42

在写VIJOS P1131时出现这种情况!

program P1131;
var p,q:array[0..500000] of longint;
    xo,yo:longint;
    i,j,s,sum,yue:longint;
procedure judge(a,b:longint);
var c:longint;
begin
yue:=-1;
if a<b then begin c:=a;a:=b;b:=c; end;
if (a mod b=0) then yue:=b else
 begin
  c:=a mod b;
  judge(b,c);
 end;
end;
begin
  readln(xo,yo);
  repeat
  inc(s);
  p[s]:=xo*s;q[s]:=xo*s;
  until (xo*s>=yo);
  for i:=1 to s do
    for j:=s downto 1 do
    begin
     if ((p[i]*q[j]/xo)=yo) then
     begin
      judge(p[i],q[j]);
       if (yue=xo) then
        inc(sum);
      end;
     end;
    writeln(sum);
end.

我吧judge写成一个函数 BOOLEAN 然后if ((p[i]*q[j]/xo)=yo) and (judge(p[i],q[j])=xo) then inc(sum);奇怪的是用3 60 做测试时12 和 15却不能让sum+1..为什么??

最佳答案
  • 二级知识专家网友:抚弦思华年
  • 2021-08-13 10:36

var
  i,j,ans:longint;
  n,m,s:qword;
function check(m:longint):boolean;
var j:longint;
begin
   if m=1
   then exit(false);
   if m=2
   then exit(true);
   if not odd(m)
   then exit(false);
   for j:=3 to round(sqrt(m)) do
    if m mod j =0
    then exit(false);
   exit(true);
end;
begin
  readln(n,m);
  if m mod n <>0
  then begin
    writeln(0);
    halt;
    end;
  ans:=0;
  s:=m div n;
  for i:=1 to s do
   if (s mod i=0)and(check(i))
   then inc(ans);
  writeln(ans*2);
end.


看不懂你的


贴上我的标程算了

全部回答
  • 1楼网友:为你卑微了我自己
  • 2021-08-13 11:22

function judge(a,b:longint):longint; var c:longint; begin if a<b then begin c:=a;a:=b;b:=c; end; if (a mod b=0) then judge:=b else  begin   c:=a mod b;   exit(judge(b,c));  end; end;  

为什么我改的就是对的???

我要举报
如以上问答内容为低俗/色情/暴力/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
点此我要举报以上问答信息
推荐资讯