Cod sursa(job #1473866)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 20 august 2015 13:12:47
Problema Fibo3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int NMax = 105;

long long int v[NMax];

inline void precalc(){
    v[1] = v[2] = 1;
    for(int i = 3; i < NMax; i++){
        v[i] = v[i - 1] + v[i - 2];
    }
}

int main(){
    long long int n, x, y, X, Y, ans;
    fin >> n;
    precalc();
    while(n--){
        fin >> x >> y >> X >> Y;
        ans = 0;
        for(int i = 2; i < NMax && v[i] <= (X + Y); i++){
            if(v[i] >= x + y){
                ans += min(X, v[i] - y) - max(x, v[i] - Y) + 1;
            }
        }
        fout << ans << "\n";
    }
    return 0;
}