quadratic equation 17年省赛F题,SDUT 3898

题目

quadratic equation

Time Limit: 2000MS  Memory Limit: 131072KB
Problem Description

With given integers a,b,c, you are asked to judge whether the following statement is true: "For any x, ifa+bx+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
题目大意

   题目要求我们来判断一句话是否为真,“对于任何x,如果a+bx+c=0,那么x是一个整数"


解题思路


 看到这里我们基本上就可以判断的出来这是个离散数学中最基本的蕴含式,也就是大家所熟知的P->Q

  

  F代表False,T代表True

  所以我们可以把a+bx+c=0设为P,把x是一个整数设为Q

  通过图片我们可以获知如果P为false,那么这句话一定为真,P为false的时候是a+bx+c=0无解的时候

   如果P为true,那么只有Q也为true的时候这句话才为真,这种情况是等式有解且两个解都是整数的时候

   这里有一个坑就是a,b,c都是零的时候是一个假命题,当时疏忽了倒是WA了好几次

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int T;
    scanf("%d",&T);
    int ans[20]={0,1,4,9,16,25,36,49,64,81,100,121};
    while(T--)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        int dt=b*b-4*a*c;
        if(a==0)
        {
            if(b==0)
            {
                if(c==0)
                printf("NO\n");
                else
                printf("YES\n");
            }
            else if(b!=0)
            {
                if(c%b==0)
                 printf("YES\n");
                else
                printf("NO\n");
            }
        }
        else
        {
            if(dt>=0)//有解的时候
            {
                int flag=0;
                int sq_dt;
                for(int i=0;i<12;i++)
                {
                    if(dt==ans[i])
                    {
                        flag=1;
                        sq_dt=i;
                        break;
                    }
                }
                if(flag)
                {
                    if(((-b+sq_dt)%(2*a)==0)&&((-b-sq_dt)%(2*a)==0))
                    {
                        printf("YES\n");
                    }
                    else
                    {
                        printf("NO\n");
                    }
                }
                else
                {
                    printf("NO\n");
                }
            }
            else//无解的时候
            {
              printf("YES\n");
            }

        }
    }
   return 0;
}



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值