Cod sursa(job #1453742)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 24 iunie 2015 15:48:57
Problema Fibo3 Scor 0
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;
}