Title:
Give you a proposition: "For any x, if
, then x is an integer." For any x, if
, then x is an integer.
Let you judge the proposition is true or false, output YES, NO;
analyze:
Judge all possibilities:
a | b | c | describe |
---|---|---|---|
0 | 0 | 0 | x is any real number, eg.x = 0.1 makes the equation 0, but x is not an integer |
0 | 0 | !0 | For any x, the equation is not 0, so the proposition is true |
0 | !0 | !0 | bx + c = 0; x = c/b, if c/b is an integer, x is an integer, otherwise not |
!0 | - | - | Unary quadratic equation, find the root formula, determine whether x1, x2 are integers |
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define debug cout<<"**********"<<endl;
#define ll long long
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
using namespace std;
const int maxn = 10000;
const int mod = 1e9+7;
int main()
{
std::ios::sync_with_stdio(false);
int T;
cin>>T;
double a,b,c;
while(T--)
{
cin>>a>>b>>c;
if(a == 0)
{
if(b == 0)
{
if(c == 0)
{
no;
}
else
{
yes;
}
}
else
{
if((int)c%(int)b == 0)
{
yes;
}
else
{
no;
}
}
}
else
{
double k = b*b-4*a*c;
if(k < 0)
{
yes;
}
else
{
double d = sqrt(k);
double x1 = (-b+d)/(2*a);
double x2 = (-b-d)/(2*a);
int xx1 = x1;
int xx2 = x2;
if(x1 - xx1 ==0 && x2 - xx2 == 0)
{
yes;
}
else
{
no;
}
}
}
}
return 0;
}