Pagini recente » Cod sursa (job #2745567) | Cod sursa (job #1862857) | Cod sursa (job #636193) | Cod sursa (job #1637966) | Cod sursa (job #2406233)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("fibo3.in");
ofstream fout("fibo3.out");
const long long MAXSUM = 2e15;
vector <long long> fibo;
void InitFibo()
{
fibo.push_back(1);
int cursor = 1;
long long current = 2;
while(current <= MAXSUM)
{
fibo.push_back(current);
cursor++;
current = fibo[cursor - 1] + fibo[cursor - 2];
}
}
void Solve()
{
long long x1, x2, y1, y2;
fin >> x1 >> y1 >> x2 >> y2;
long long ans = 0;
for(auto it : fibo)
if(x1 + y1 <= it && it <= x2 + y2)
{
long long dif = min(it - x1 - y1, x2 + y2 - it);
if(dif < min(x2 - x1, y2 - y1))
ans += (dif + 1);
else
ans += 1 + min(x2 - x1, y2 - y1);
}
fout << ans << '\n';
}
int main()
{
InitFibo();
int t; fin >> t;
while(t--)
Solve();
return 0;
}