Pagini recente » Cod sursa (job #3269994) | Borderou de evaluare (job #2298052) | Borderou de evaluare (job #878082) | Cod sursa (job #2323410) | Cod sursa (job #466510)
Cod sursa(job #466510)
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <limits.h>
#include <iomanip>
#include <ctime>
#include <malloc.h>
#include <new>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <list>
#include <deque>
#include <numeric>
#include <functional>
#include <cassert>
#include <sstream>//string stream
//#include <utility>
// #include <classic_algorithms>
// #include <creativity>
//static bool sync_with_stdio( bool sync = false ); //->daca nu vreau sa folosesc elemente C, pt a mari viteza
using namespace std;
#define infile "fibo3.in"
#define outfile "fibo3.out"
bool isFib( int x )
{
if( x == 0 )
return false;
double X1 = 5 * x * x + 4;
double X2 = 5 * x * x - 4;
int X1_sqrt = (int)sqrt(X1);
int X2_sqrt = (int)sqrt(X2);
return ( ( (X1_sqrt * X1_sqrt == X1) || (X2_sqrt * X2_sqrt == X2) ) ? true : false );
}
int main()
{
//int timp_exec=clock(); | no longer necessary with Code::Blocks
int n,
x1,x2,y1,y2,
suma;
freopen(infile,"r",stdin);
freopen(outfile,"w",stdout);
scanf("%d",&n);
for(register int i=0;i!=n;++i)
{
suma=0;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1==x2)
{
printf("%d\n",y2-y1+1);
}
else if(y1==y2)
{
printf("%d\n",x2-x1+1);
}
//vreun alt caz particular????????????????????//-----------------------
else
{
if( isFib( x1+y1 ) ) ++suma;
if( isFib( x1+y2 ) ) ++suma;
if( isFib( x2+y2 ) ) ++suma;
if( isFib( x2+y1 ) ) ++suma;
printf("%d\n",suma);
}
}
fclose(stdout);
fclose(stdin);
//-----------------------
//long double x;
//cout.setf(ios::fixed);
//cout<<setprecision(0)<<x;
//-----------------------
//timp_exec=clock()-timp_exec; | no longer necessary with Code::Blocks
//cout<<timp_exec; | no longer necessary with Code::Blocks
return 0;
}