Cod sursa(job #1416509)

Utilizator MaarcellKurt Godel Maarcell Data 8 aprilie 2015 11:08:09
Problema Fibo3 Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <fstream>
#define LL long long
using namespace std;

LL N,x1,y1,x2,y2,F[80];

int main(){
    ifstream fin("fibo3.in");
    ofstream fout("fibo3.out");
    fin >> N;

    int i;
    F[0]=F[1]=1;
    for (i=2; i<=70; i++) F[i]=F[i-1]+F[i-2];

    LL X1,Y1,X2,Y2,res;
    while (N--){
        fin >> x1 >> y1 >> x2 >> y2;
        res=0;
        for (i=1; i<=70; i++){
            X1=F[i]-y2;
            Y1=F[i]-y1;
            X2=x1;
            Y2=x2;
            if (X1>X2){
                swap(X1,X2);
                swap(Y1,Y2);
            }

            if (Y2<=Y1) res+=(Y2-X2+1);
            else if (X2<=Y1) res+=(Y1-X2+1);
        }

        fout << res << "\n";
    }

    return 0;
}