牛牛的方程式【模拟】

Description–

牛牛最近对三元一次方程非常感兴趣。众所周知,三元一次方程至少需要三个方程组成一个方程组,才有可能得出一组解。

牛牛现在想要知道对于方程 a x + b y + c z = d ax+by+cz=d ax+by+cz=d 中有没有至少存在一组 x , y , z x,y,z x,y,z 的解,且 x , y , z x,y,z x,y,z 都为整数,使得方程式成立


Input–

第一行输入一个正整数 T T T,表示测试点中测试样例的组数。

接下来 T T T 行,每行四个整数 a , b , c , d a,b,c,d a,b,c,d 表示方程 a x + b y + c z = d ax+by+cz=d ax+by+cz=d 中的 a , b , c , d a,b,c,d a,b,c,d

Output–

如果至少存在一组{x,y,z}能够满足方程式等式成立,且x,y,z均为整数,请输出"YES",否则请输出"NO"。


Sample Input–

2
3 1 2 0
2 8 8 3

Sample Output–

YES
NO

说明–

  • 1 ∗ 3 + ( − 1 ) ∗ 1 + ( − 1 ) ∗ 2 = 0 1*3+(-1)*1+(-1)*2=0 13+(1)1+(1)2=0
    得到一组 x , y , z x,y,z xyz 的解为{ 1 , − 1 , − 1 1,-1,-1 1,1,1 }为整数使得等式成立,所以输出 " Y E S " "YES" "YES"
    不存在x,y,z为整数使得方程 2 x + 8 y + 8 z = 3 2x+8y+8z=3 2x+8y+8z=3 成立,所以输出 " N O " "NO" "NO"

对于 10 % 10\% 10% 的测试数据,保证 T = 1 , − 10 ≤ a , b , c , d ≤ 10 T=1,-10 \leq a,b,c,d \leq10 T=1,10a,b,c,d10
对于 30 % 30\% 30% 的测试数据,保证 − 100 ≤ a , b , c , d ≤ 100 -100 \leq a,b,c,d\leq 100 100a,b,c,d100
对于 100 % 100\% 100% 的测试数据,保证 − 1 0 18 ≤ a , b , c , d ≤ 1 0 18 , 1 ≤ T ≤ 100 -10^{18}\leq a,b,c,d\leq 10^{18} ,1 \leq T \leq 100 1018a,b,c,d1018,1T100


解题思路–

就是算 g c d ( a , b , c ) gcd(a, b, c) gcd(a,b,c) 能不能被 d d d 整除,可就 y e s yes yes


代码–

#include <iostream>
#include <cstdio>

using namespace std;

int t;
long long a, b, c, d;

long long gcd(long long x, long long y)
{
	if (!y) return x;
	return gcd(y, x % y);
}

void work()
{
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	if (a == 0)
	{
		if (b == 0)
		{
			if (c == 0)
			{
				if (d == 0) printf("YES");
				else printf("NO");
			}
			else if (d == 0 || d % c == 0) printf("YES");
			else printf("NO");
		}
		else if (c == 0)
		{
			if (d == 0 || d % b == 0) printf("YES");
			else printf("NO");
		}
		else if (d == 0 || d % gcd(b, c) == 0) printf("YES");
		else printf("NO");
	}
	else if (d == 0 || d % gcd(gcd(a, b), c) == 0)printf("YES");
	else printf("NO");
	
	printf("\n");
}

int main()
{
	scanf("%d", &t);
	for (int i = 1; i <= t; ++i)
	  work();
	
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值