Pagini recente » Cod sursa (job #2535663) | Cod sursa (job #690106) | Cod sursa (job #1648922) | Cod sursa (job #2280526) | Cod sursa (job #514401)
Cod sursa(job #514401)
#include <stdio.h>
#define Nmax 100002
#define Fmax 102
#define Vmax 2000000000000000LL
#define LL long long
LL F[Fmax],sol;
int T;
inline LL Abs(LL x){ return x>0? x:-x; }
inline LL Minim(LL x,LL y){ return x<y ? x:y; }
int main(){
int i,j,x1,x2,y1,y2,N;
freopen("fibo3.in","r",stdin);
freopen("fibo3.out","w",stdout);
F[1]=1; F[2]=2;
for(i=3; F[i-1]+F[i-2]<=Vmax; ++i) F[i]=F[i-2]+F[i-1];
N=i-1;
scanf("%d",&T);
for(i=1;i<=T;++i){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
sol=0;
for(j=1; j<=N; ++j){
if( F[j]<x1+y1 ) continue;
if( F[j]>x2+y2 ) break;
if( F[j]<=x1+y2)
sol+=Minim(F[j]-x1-y1+1,x2-x1+1);
else sol += Minim(x2+y2-F[j]+1,y2-y1+1);
}
printf("%lld\n",sol);
}
fclose(stdin); fclose(stdout);
return 0;
}