细节
With given integers a,b,c, you are asked to judge whether the following statement is true: "For any x, if a x2 +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.
Sample Input
3 1 4 4 0 0 1 1 3 1
Sample Output
YES YES NO
题意:
给你三个数,a,b,c问这三个数构成的一元二次方程有没有非整数根,(如果有根,则一定整数,如果命题成立,输出yes 否则输出no),没有根的情况为yes。
#include <iostream> #include<cstdio> #include<algorithm> #include<cmath> #define minn 1e-8 using namespace std; int main() { int t,a,b,c,ans; double ans1; cin>>t; while(t--) { cin>>a>>b>>c; if(a==0) { if(b!=0) { if(c%b!=0) printf("NO\n"); else printf("YES\n"); } else { if(c==0) printf("NO\n"); else printf("YES\n"); } } else { double der=b*b-4*a*c; if(der<0) { printf("YES\n"); } else { double dd=sqrt(der); int dd1=int(sqrt(der)); if(abs(dd1-dd)<minn&&((-b+dd1)%(2*a)==0&&(-b-dd1)%(2*a)==0)) printf("YES\n"); else printf("NO\n"); } } } return 0; }