Pagini recente » Cod sursa (job #1357180) | Cod sursa (job #2091171) | Cod sursa (job #380702) | Cod sursa (job #2363169) | Cod sursa (job #1860312)
#include <cstdio>
long long n, x1, y1, x2, y2;
inline long long calc(long long x){
long long a, rx, ry;
a = x - x1;
if(a <= y2){
rx = x1;
ry = a;
}
else{
ry = y2;
rx = x - y2;
}
if(ry - y1 + 1 < x2 - rx + 1)
return ry - y1 + 1;
else
return x2 - rx + 1;
}
int main(){
FILE *in = fopen("fibo3.in", "r");
FILE *out = fopen("fibo3.out", "w");
long long rez, a, b;
fscanf(in, "%lld", &n);
for(; n > 0; n--){
fscanf(in, "%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
a = 1;
b = 1;
rez = 0;
while(b <= x2 + y2){
if(b >= x1 + y1)
rez += calc(b);
b = a + b;
a = b - a;
}
fprintf(out, "%lld\n", rez);
}
fclose(in);
fclose(out);
return 0;
}