Cod sursa(job #1453767)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 24 iunie 2015 17:57:46
Problema Fibo3 Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <cstdio>
#include <algorithm>

#define NMAX 107

using namespace std;

int a[NMAX];
long long X1, Y1, X2, Y2, Ans;
int T;

int main(){
    freopen("fibo3.in", "r", stdin);
    freopen("fibo3.out", "w", stdout);
    scanf("%d", &T);
    a[1] = a[2] = 1;
    for(int i = 3; i <= 100; ++i)
        a[i] = a[i - 1] + a[i - 2];
    while(T){
        --T;
        scanf("%lld %lld %lld %lld", &X1, &Y1, &X2, &Y2);
        Ans = 0;
        for(int i = 2; i <= 100; ++i){
            if(a[i] < X1 + Y1)
                continue;
            if(a[i] > X2 + Y2)
                break;
            Ans += min(X2, a[i] - Y1) - max(X1, a[i] - Y2) + 1;
        }
        printf("%lld\n", Ans);
    }
    return 0;
}