quadratic equation



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, if a+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
Hint
Author
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学) 
P     Q    P->Q
0     0         1
0     1         1
1     0         0
1     1         1

若条件P为假命题  结论无所谓  该命题就是真明题

即不满足 a+ bx+ c=0则输出YES

若满足  a+ bx+ c=0 那么只有x为整数就输出YES,否则输出NO 
import java.util.*;
import java.math.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int T;
		Scanner in=new Scanner(System.in);
		T=in.nextInt();
		for(int i=0;i<T;i++)
		{
			int flag=0;
			int a,b,c;
			a=in.nextInt();
			b=in.nextInt();
			c=in.nextInt();
			if(a==0&&b==0)
			{
				if(c==0)
				{
					System.out.println("NO");
				}
				else
				{
					System.out.println("YES");
				}
				
			}
			else if(a==0&&b!=0)
			{
				if(c%b!=0)
				{
					System.out.println("NO");
				}
				else
				{
					System.out.println("YES");
				}
			}
			else if(a!=0)
			{
				int b2=b*b-4*a*c;
				if(b2<0)
				{
					System.out.println("YES");
				}
				else
				{
					double sq=Math.sqrt(b2);
					double a1=(-b+sq)/(2*a);
					double a2=(-b-sq)/(2*a);
					double Inta1=(int)(a1);
					double Inta2=(int)(a2);
					
					if((a1-Inta1==0)&&(a2-Inta2==0))
					{
						System.out.println("YES");
					}
					else
					{
						System.out.println("NO");
					}
				}
			}
		}
	}

}
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值