Cod sursa(job #1239173)

Utilizator EpictetStamatin Cristian Epictet Data 8 octombrie 2014 14:29:16
Problema Fibo3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
using namespace std;
ifstream fin ("fibo3.in");
ofstream fout ("fibo3.out");
long long N, x1, y1, x2, y2, V[85];

int main()
{
    V[1] = V[2] = 1;
    for (int i=3; i<=75; i++) V[i] = V[i-1] + V[i-2];

    fin >> N;
    for (int i=1; i<=N; i++)
    {
        fin >> x1 >> y1 >> x2 >> y2;
        long long j = 2, sum = 0;
        while (V[j] < x1 + y1) j++;
        while (V[j] <= x2 + y2)
        {
            sum += min(x2, V[j]-y1) - max(x1, V[j]-y2) + 1;
            j++;
        }
        fout << sum << '\n';
    }
    fout.close();
    return 0;
}