牛牛的方程式
牛牛的方程式
https://ac.nowcoder.com/acm/contest/7605/A
ax+by=c有解结论的推广
gcd(a,b)|c
别忘了特判a=b=0的时候,c=0,c/=0情况
代码:
#include<bits/stdc++.h> using namespace std; #define int long long signed main() { int t; cin >> t; while(t--) { int a, b, c, d; cin >> a >> b >> c >> d; int g = __gcd(__gcd(a, b),c); if(a == 0 && b == 0 && c == 0) { if(d != 0) cout << "NO" << '\n'; else cout << "YES" << '\n'; continue; } if(d % g == 0) { cout << "YES" << '\n'; } else { cout << "NO" << '\n'; } } }