Cod sursa(job #466336)

Utilizator Marius96Marius Gavrilescu Marius96 Data 26 iunie 2010 13:09:34
Problema Fibo3 Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2010, gimnaziu si clasa a IX-a, Ziua 2 Marime 2.41 kb
#include <cstdio>
#include <cstring>
const unsigned long long int fib[73]={
1ULL, 2ULL, 3ULL, 5ULL, 8ULL, 13ULL, 21ULL, 34ULL, 55ULL, 89ULL, 144ULL, 233ULL, 377ULL, 610ULL, 987ULL, 1597ULL, 2584ULL, 4181ULL, 6765ULL, 10946ULL, 17711ULL,
28657ULL, 46368ULL, 75025ULL, 121393ULL, 196418ULL, 317811ULL, 514229ULL,832040ULL, 1346269ULL, 2178309ULL, 3524578ULL, 5702887ULL, 9227465ULL, 14930352ULL,
24157817ULL, 39088169ULL, 63245986ULL, 102334155ULL, 165580141ULL, 267914296ULL, 433494437ULL, 701408733ULL,1134903170ULL, 1836311903ULL, 2971215073ULL,
4807526976ULL, 7778742049ULL, 12586269025ULL, 20365011074ULL, 32951280099ULL, 53316291173ULL, 86267571272ULL, 139583862445ULL, 225851433717ULL,365435296162ULL,
591286729879ULL, 956722026041ULL, 1548008755920ULL, 2504730781961ULL, 4052739537881ULL, 6557470319842ULL, 10610209857723ULL, 17167680177565ULL, 27777890035288ULL,
44945570212853ULL, 72723460248141ULL, 117669030460994ULL, 190392490709135ULL, 308061521170129ULL, 498454011879264ULL, 806515533049393ULL, 1304969544928657ULL};
unsigned long long x1,x2,y1,y2;
class Huge{
public:
    char v[50];
    int l;
    Huge(){
        null();
    }
    void null(){
        memset(v,0,50*sizeof(char));
        l=0;
    }
    void operator+=(unsigned long long int X){
        int pl=0;
        while(X){
            v[pl]+=X%10;
            X/=10;
            v[pl+1]+=v[pl]/10;
            v[pl]=v[pl]%10;
            pl++;
        }
        for(int i=0;i<50;i++)
            if(v[i])
                l=i;
    }
    void print(){
        for(int i=l;i>=0;i--)
            printf("%d",v[i]);
        printf("\n");
    }
}ans;
inline void doSomething(int nr){
    int i1;
    //START CALC i1
    if(x1+y2>nr)
        i1=x1;
    else
        i1=nr-y2;
    //END CALC i1
    int i2;
    //START CALC i2
    if(y1+x2>nr)
        i2=nr-y1;
    else
        i2=x2;
    //END CALC i2
    ans+=(i2-i1+1);
}
int main(){
    freopen("fibo3.in","r",stdin);
    freopen("fibo3.out","w",stdout);
    int n=1;
    scanf("%d",&n);
    while(n--){
        scanf("%llu%llu%llu%llu",&x1,&y1,&x2,&y2);
        if(x1>x2){
            int tmp=x1;
            x1=x2;
            x2=tmp;
        }
        if(y1>y2){
            int tmp=1;
            y1=y2;
            y2=tmp;
        }
        ans.null();
        for(int i=0;i<73;i++){
            if(y2+x2<fib[i])
                break;
            if(x1+y1<=fib[i])
                doSomething(fib[i]);
        }
        ans.print();
    }
}