COJ 1204

#include 
#include 
#include 
using namespace std;
int main()
{
	int T;
	scanf("%d", &T);
	long long L, A, B;
	while(T--)
	{
		scanf("%lld %lld %lld", &L, &A, &B);
		if(L % 2 != 0)
		{
			printf("0\n");
		}
		else
		{
			long long maxn = L/4, minn = 1;
            long long l = 0;
            while(minn <= maxn)
            {  
	            long long mid = (maxn + minn) / 2;  
	            if(mid * (L/2 - mid) < A)
	            {  
		            l = max(l, mid);  
		            minn = mid + 1;  
	            }  
	            else  
	            	maxn = mid - 1;
            }  
            long long r = 0;
            maxn = L/4, minn = 1;
            while(minn <= maxn)
            {  
	            long long mid = (maxn + minn) / 2;
	            if(mid * (L/2-mid) <= B)
	            {
	                r = max(r, mid);
	                minn = mid + 1;
	            }
	            else
	    			maxn = mid - 1;
            }
            printf("%lld\n", r - l);
		}
	} 
	return 0;
}

你可能感兴趣的:(ACM)