Pagini recente » Cod sursa (job #2728304) | Cod sursa (job #387462) | Cod sursa (job #2771062) | Cod sursa (job #2871295) | Cod sursa (job #1860309)
#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 = 2;
rez = calc(1);
while(b <= x2 + y2){
rez += calc(b);
b = a + b;
a = b - a;
}
fprintf(out, "%lld\n", rez);
}
fclose(in);
fclose(out);
return 0;
}