Pagini recente » Cod sursa (job #2359808) | Cod sursa (job #2687426) | Cod sursa (job #2716842) | Cod sursa (job #2357924) | Cod sursa (job #2015822)
#include <bits/stdc++.h>
using namespace std;
const int DIM = 1e2;
const long long INF = 1e16;
long long fib[DIM];
int main(void) {
freopen("fibo3.in", "r", stdin);
freopen("fibo3.out", "w", stdout);
int n = 1;
fib[0] = fib[1] = 1;
while (fib[n] + fib[n - 1] <= INF)
++n, fib[n] = fib[n - 1] + fib[n - 2];
int q;
scanf("%d", &q);
while (q--) {
long long x1, y1, x2, y2, ans = 0;
scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
for (int i = 1; i <= n; ++i) {
if (fib[i] - x1 < y1 or fib[i] - x2 > y2)
continue;
long long p1 = x1 + max((fib[i] - x1) - y2, 0LL),
p2 = x2 - max(y1 - (fib[i] - x2), 0LL);
ans += p2 - p1 + 1;
}
printf("%lld\n", ans);
}
return 0;
}