quadratic equation
Time Limit: 2000MS
Memory Limit: 131072KB
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 blablabla:明明是道挺水的题 做的我怎么就这样了呢。。。做题最怕的就是没自信了吧 我是个怎样的人呢 这是我经常想的东西吧 回归正题,刚开始是分别列出满足和不满足的情况 后来发现总容易考虑不周,干脆就找其中一个的情况 这和离散有不小关系 先是那个如果前提不成立 那么命题也是真的。。然后就是0 0 0的坑。。。 这个真的是被队友带了节奏 我还不思考 唉
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main()
{
int T;
int i,j;
int a,b,c;
double x1,x2;
while(cin>>T)
{
while(T--)
{
int flag=0;
cin>>a>>b>>c;
if(a==0&&b==0&&c==0)
{
flag=0;
}
else if(a==b&&b==0&&c!=0)
{
flag=1;
}
else if(a==0&&b!=0)
{
if((-c)%b==0)
{
flag=1;
}
}
else if(c==0&&a!=0)
{
if((-b)%a==0)
{
flag=1;
}
}
else if(b==0&&a!=0&&c<=0)
{
if(a!=0&&b==0&&c==0)
{
flag=1;
}
else
{
x1=(-c)*1.0/a;
x1=sqrt(x1);
if((int)x1==x1)
{
flag=1;
}
}
}
else if(a!=0)
{
int dt=b*b-4*a*c;
if(dt<0) flag=1;
else if(dt>=0)
{
x1=(-b+(double)sqrt(dt))*1.0/(2*a);
x2=(-b-(double)sqrt(dt))*1.0/(2*a);
if((int)x1==x1&&(int)x2==x2)
{
flag=1;
}
}
}
if(flag)
{
printf("YES\n");
}
else printf("NO\n");
}
}
return 0;
}