Pagini recente » Cod sursa (job #595099) | Cod sursa (job #839253) | Cod sursa (job #1561809) | Cod sursa (job #1167076) | Cod sursa (job #2253698)
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
long long v[80];
long long x, y, s;
long long aparitii(long long n)
{
n-=s;
int m;
if (n<=x)
m=n+1;
else
m=x+y-n+1;
if (m>=y+1)
m=y+1;
return m;
}
long long ans(long long x, long long y)
{
int i;
long long sum=0;
for(i=1; i<=75; i++)
{
if (v[i]<=x+y+s && v[i]>=s)
sum+=aparitii(v[i]);
if (v[i]>x+y+s)
break;
}
return sum;
}
int main()
{
freopen("fibo3.in", "r", stdin);
freopen("fibo3.out", "w", stdout);
int i, n;
v[0]=v[1]=1;
for(i=2; i<=75; i++)
v[i]=v[i-1]+v[i-2];
long long x1, x2, y1, y2;
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
s=x1+y1;
x=x2-x1;
y=y2-y1;
if (x<y)
{
x1=x;
x=y;
y=x1;
}
printf("%lld\n", ans(x, y));
}
return 0;
}