Cod sursa(job #466123)

Utilizator MihaicorneliuMihai Pojar Mihaicorneliu Data 26 iunie 2010 10:49:12
Problema Fibo3 Scor 30
Compilator fpc Status done
Runda Stelele Informaticii 2010, gimnaziu si clasa a IX-a, Ziua 2 Marime 1.44 kb
program fibo3;
type vector=array[0..80] of int64;
var a:vector;
    i,o:text;
    x1,x2,y1,y2,s1,s2,dx,dy,g,p,rez:int64;
    n,h,li,lf,lc,f,pi,pf:longint;
procedure sirfibo;
var c:integer;
begin
  a[0]:=0;
  a[1]:=1;
  a[2]:=2;
  for c:=3 to 76 do
      a[c]:=a[c-1]+a[c-2]
end;
begin
  sirfibo;
  assign(i,'fibo3.in');
  reset(i);
  assign(o,'fibo3.out');
  rewrite(o);
  readln(i,n);
  for h:=1 to n do
    begin
      rez:=0;
      readln(i,x1,y1,x2,y2);
      s1:=x1+y1;
      s2:=x2+y2;
      dx:=x2-x1;
      dy:=y2-y1;
      li:=0;
      lf:=76;
      repeat
        lc:=(li+lf) div 2;
        if s1<=a[lc] then
          lf:=lc
        else
          li:=lc
      until abs(li-lf)=1;
      pi:=lf;
      li:=0;
      lf:=76;
      repeat
        lc:=(li+lf) div 2;
        if s2<a[lc] then
          lf:=lc
        else
          li:=lc
      until abs(li-lf)=1;
      pf:=li;
      for f:=pi to pf do
        if dx<dy then
          begin
            g:=x1;
            repeat
              p:=a[f]-g;
              if (p>=y1)and(p<=y2) then
                rez:=rez+1;
              g:=g+1
            until g>x2
          end
        else
          begin
            g:=y1;
            repeat
              p:=a[f]-g;
              if (p>=x1)and(p<=x2) then
                rez:=rez+1;
              g:=g+1
            until g>y2
          end;
      writeln(o,rez)
  end;
  close(o)
end.