当前位置: 代码迷 >> 综合 >> 第八届ACM山东省赛 F quadratic equation
  详细解决方案

第八届ACM山东省赛 F quadratic equation

热度:55   发布时间:2023-12-11 17:39:08.0

quadratic equation

Time Limit: 2000MS Memory Limit: 131072KB
Submit Statistic

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

Hint

Author

“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)


分析:会if就能做,条件判断入门题


#include <bits/stdc++.h>using namespace std;int main()
{int t;cin>>t;while(t--){int a,b,c;cin>>a>>b>>c;if(a==0 && b==0 ){if(c==0){puts("NO");continue;}else{puts("YES");continue;}}else if(a==0 && b!=0){if(c%b !=0){puts("NO");continue;}else{puts("YES");continue;}}else if(a!=0){int dt=b*b-4*a*c;if(dt<0){puts("YES");continue;}else{double kg=sqrt(dt);if(((-b+kg)/(2*a)) - (int)((-b+kg)/(2*a))==0 && ((-b-kg)/(2*a))- (int)((-b-kg)/(2*a))==0 ){puts("YES");continue;}else{puts("NO");continue;}}}}return 0;
}