include<stdio.h>
include<math.h>
int main(){
int a,t,i; double y,z; scanf("%d",&t); for(i = 0; i < t; i++){ scanf("%d",&a); if(a == 1){ printf("N\n"); } else{ y = ((double)a + sqrt((double)a*(double)a - 4*(double)a))/2; z = ((double)a - sqrt((double)a*(double)a - 4*(double)a))/2; printf("Y %0.9lf %0.9lf\n",y,z); } } return 0;
why this code shows wrong answer(1076 C)
Auto comment: topic has been updated by zarif_2002 (previous revision, new revision, compare).
The problem solution has three cases:
if d = 0, then the answer is Yes, and a = b = 0.
if d = 1, 2, or 3, then the answer is No.
if d > 3, then the answer is Yes, a = c (1+e) and b = c (1-e), where c = d/2 and e = sqrt(1-2/c).
But d can be double. So in the second case you should only check if 0<d<4.
Please check the problem statement.
1076C - Meme Problem
d in each test case is restricted to integers between 0 and 1000.
45710401
It is because you do not check if discriminant is lower then zero, but check if a==1 instead. And if D is equal to zero, you should output only one root (actually there will be two same roots).
In this problem you literally have to solve a + b = d, a * b = d when d is given. The resulting equation after substituting ( for example b = d — a ) into the second equation will be -a^2 + ad — d = 0 ( a quadratic equation ), it has no solutions for real numbers when a * a — 4 * a < 0.