裴蜀定理的推广,若,则,负数可以转化为正数处理
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <queue> #define int long long using namespace std; const int N = 1e6 + 10, M = 2e6 + 10, inf = 0x3f3f3f3f; inline int read() { int res = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); return res; } int n, m, cnt, a[4], d; int gcd(int a, int b) {return b ? gcd(b, a % b) : a;} signed main() { int T = read(); while (T--) { a[1] = read(); a[2] = read(); a[3] = read(); d = read(); if (a[1] == 0 && a[2] == 0 && a[3] == 0) { printf(d ? "NO\n" : "YES\n"); continue; } if (d == 0) {printf("YES\n"); continue;} int p = 1, c = a[p]; while(!c && p <= 3) c = a[++p]; for (int i = p; i <= 3; i++) { if (a[i]) c = gcd(c, a[i]); } if (c > d) {printf("NO\n"); continue;} if (gcd(c, d) != c) {printf("NO\n"); continue;} printf("YES\n"); } return 0; }