|  | 
|  | 
| back to board | Wht's my error? program t1320;
 
 var
 u,v,t : int64;
 f,maxl,maxr : int64;
 il1,il2,jl1,jl2 : int64;
 
 function GetLevel1 (i:integer):int64;
 var t : int64;
 begin
 t := (Trunc (sqrt ((i))));
 if sqr (t)<i then Result := t+1
 else Result := t;
 end;
 
 function GetLevel2 (i:int64):int64;
 var
 b : byte;
 begin
 f := GetLevel1 (i);
 b := ((f and 1)*2) + (i and 1);
 if (b=0) or (b=3) then Result := 2*F-1
 else Result := 2*(F-1);
 end;
 
 function GetMaxOnLev (Level : int64):int64;
 begin
 Result := sqr (Level);
 end;
 
 function GetMinOnLev (Level : int64) : int64;
 begin
 Result := sqr (Level-1)+1;
 end;
 
 function ComputePath : int64;
 begin
 il1 := GetLevel1 (u); il2 := GetLevel2 (u);
 jl1 := GetLevel1 (v); jl2 := GetLevel2 (v);
 if (u=v) then begin REsult :=0; exit; end;
 if (u=1) then begin Result := jl2-il2; exit; end;
 if (il2=jl2) then begin Result := v-u; exit; end;
 if (il2 and 1)=1 then
 begin
 maxl := GetMinOnLev (jl1)-GetMinOnLev(il1)+u;
 maxr := GetMaxOnLev (jl1)-GetMaxOnLev(il1)+u;
 end
 else
 begin
 maxl := GetMinOnLev (jl1)+(u-1)-GetMinOnLev(il1);
 maxr := GetMaxOnLev (jl1)-GetMaxOnLev(il1)+u+1;
 end;
 if v < maxl then Result := jl2-il2+(maxl-v) else
 if v > maxr then Result := jl2-il2-(v-maxr) else
 Result := jl2-il2;
 end;
 
 begin
 Read (u,v);
 if (u>v) then begin t:=u; u:=v; u:=t; end;
 WriteLn (ComputePath);
 end.
 
 Edited by author 19.07.2005 18:28
 | 
 | 
|