carneiro wrote:alright, i've written both solutions, one with doubles and another with integers and my hand-made sqrt with binary search, using long long, and both still WA.
My Baskara coeficients are :
a = 2;
b = ((-3)*P) - Q;
c = P*P;
this is for finding (y*y). Isn't that wrigth Shahriar ?
I got the same coefficients as carneiro's.
But I have a problem, how can I determine whether b*b-4ac is a square number or not?
b*b-4ac = (-3P-Q)^2 - 4*2*P^2 = P*P+6*P*Q+Q*Q
In worst case, P=Q=(2^31-1)
and P*P+6PQ+Q*Q will probably larger than 2^64 (unsigned long long)
I wander why long long or double can solve that.
Or I have to get another coeffieients?