quadratic equation
Problem Description
With given integers a,b,c, you are asked to judge whether the following statement is true: "For any x, if a⋅+b⋅x+c=0, then x is an integer."
Input
The first line contains only one integer T(1≤T≤2000), which indicates the number of test cases.
For each test case, there is only one line containing three integers a,b,c(−5≤a,b,c≤5).
Output
or each test case, output “YES
” if the statement is true, or “NO
” if not.
Example Input
3 1 4 4 0 0 1 1 3 1
Example Output
YES YES NO
#include<stdio.h>
#include <math.h>
int main ()
{
int a,b,c,i,j,t,sum;
scanf("%d",&t);
while (t--)
{
scanf("%d %d %d",&a,&b,&c);
if(a==0)
{
sum=0;
if(b==0)
{
if(c!=0) printf("YES\n");
else printf("NO\n");
}
else
{
for(i=-1000; i<=1000; i++)
{
if(b*i+c==0)
{
sum++;
}
}
if(sum==1)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
}
if(a!=0)
{
sum=0;
j=(b*b)-(4*a*c);
if(j<0 ) printf("YES\n");
else
{
for(i=-1000; i<=1000; i++)
{
if( (a*i*i)+(b*i)+c==0)
{
sum++;
}
}
if( (sum==1 &&j==0 ) || (sum==2 && j>0 ) )
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
}
}
return 0;
}