Cod sursa(job #1404993)

Utilizator felixiPuscasu Felix felixi Data 28 martie 2015 19:00:40
Problema Fibo3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <vector>
using namespace std;

ifstream fin ("fibo3.in");
ofstream fout ("fibo3.out");

vector <long long> f;

int n;
long long x[2], y[2], sol;

int main() {
    f.push_back(1);
    f.push_back(1);
    while (f.back() <= 2e15)
        f.push_back(f[f.size() - 2] + f[f.size() - 1]);
    fin >> n;
    for (int i = 1; i <= n; ++i) {
        sol = 0;
        fin >> x[0] >> y[0] >> x[1] >> y[1];
        for (int j = 1; j < f.size(); ++j) {
            long long X1 = f[j] - y[0], X2 = f[j] - y[1], now = y[1] - y[0] + 1;
            if (X1 < x[0])
                continue;
            if (X2 > x[1])
                break;
            if (X2 < x[0])
                now -= x[0] - X2;
            if (X1 > x[1])
                now -= X1 - x[1];
            sol += now;
        }
        fout << sol << "\n";
    }
}