您的位置:首页 > 其它

第八届ACM山东省赛 F quadratic equation

2017-05-18 23:27 288 查看

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;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: