ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1355. Bald Spot Revisited

Access violation on test 3. Why?
Posted by Slava Muravjev 8 Oct 2010 02:57
Why do I have access violation on test 3?
There is my cod:

var t,i,j,l:longint;
a,b,s,x:int64;
x1,x2,r:extended;
m,d:array [1..124776567] of int64;
k:array [1..20] of int64;
smena:boolean;

begin
 readln(t);
 for i:=1 to t do
  begin
   readln(a,b);
   if b mod a<>0 then k[i]:=0
    else if a=b then k[i]:=1
    else begin
     x:=round(b/a);
     s:=x;
     l:=0;
     smena:=true;
     j:=1;
     x1:=1;
     x2:=1;
     while (j<100) or (x2-x1>1e-5) do begin
      r:=x2;
      x2:=1/2*(x1+x/x1);
      x1:=r;
      inc(j);
     end;
     j:=3;
     if s mod 2=0 then
      begin
       l:=1;
       d[l]:=2;
       while (s mod 2=0) and (s<>2) do
        begin
         s:=s div 2;
         inc(m[2]);
        end;
      smena:=true;
      end;
     while (s>j) and (j<=round(x2)) do
      if s mod j=0 then
       begin
        if smena then begin smena:=false;inc(l);end;
        d[l]:=j;
        s:=s div j;
        inc(m[j]);
       end
      else begin inc(j,2);smena:=true;end;
     inc(l);
     d[l]:=s;
     inc(m[s]);
     s:=1;
     for j:=1 to l do
      begin
       if m[d[j]]<>0 then s:=s+m[d[j]];
       m[d[j]]:=0;
       d[j]:=0;
      end;
     k[i]:=s;
    end;
  end;
  for i:=1 to t do
   writeln(k[i]);
end.