当前位置: 代码迷 >> 综合 >> 端午节月赛-山东省第八届省赛 quadratic equation(多种情况,△的判断)
  详细解决方案

端午节月赛-山东省第八届省赛 quadratic equation(多种情况,△的判断)

热度:83   发布时间:2023-11-03 10:25:58.0

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
题意:
告诉你整数a, b, c, 判断命题“如果 a ? + b ? x + c =0,那么 x 为整数"是否为真命题。

思路:
就是解一元二次方程组,多了1、判断是否为整数, 2、命题逻辑的知识点

注意点:
1、判断△<0 时,命题成立;
2、等价命题“如果 x 不是整数,那么等式不成立”
3、要分别考虑a = 0, b = 0, c = 0时的情况。


#include <cstdio>
#include <iostream>
#include <map>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <cstring>
using namespace std;int main()
{int T;scanf("%d", &T);while( T --){double a, b, c;double x1, x2;cin >> a >> b >> c;if(a != 0){double d = b * b - 4 *a *c;   //判断△是否小于0if(d >= 0){d = sqrt(d);x1 = -b +d;x1 /= 2 * a;x2 = -b -d;x2 /= 2 *a;}elsex1 = x2 = 1;}else if(b != 0){x1 = -c / b;x2 = -c / b;}else if(c != 0){x1 = x2 = 1;}elsex1 = x2 = -0.5;//cout << x1 <<x2;int n1 = ceil(x1);   //判断整数的方法int n2 = ceil(x2);//cout << n1 << n2 << endl;if(n1==x1 && n2 == x2)cout << "YES" << endl;elsecout << "NO" << endl;}return 0;
}