Cod sursa(job #2406233)

Utilizator Mihai145Oprea Mihai Adrian Mihai145 Data 15 aprilie 2019 15:40:44
Problema Fibo3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#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;
}