CF1477A Nezzar and Board
作者:互联网
CF1477A Nezzar and Board
题意:
- 黑板上有 \(x_1,x_2,x_3,x_n\) 个数,可以在黑板上选择两个数,并在黑板上写上 \(2x- y\) ,求是否能在黑板上写上要求的数\(k\);
样例输入:
6
2 1
1 2
3 0
2 3 7
2 -1
31415926 27182818
2 1000000000000000000
1 1000000000000000000
2 -1000000000000000000
-1000000000000000000 123
6 80
-5 -20 13 -14 -2 -11
样例输出:
YES
YES
NO
YES
YES
NO
sol:
- 当\(x_1 == 0\) 时,可以发现当\(g = gcd(x_2,..x_n)\),\(g\) 的倍数可以全部被写在黑板上,所以当且仅当 \(k|g\) 时才可行
- 根据裴蜀定理 存在 \(x_1,x_2,x_3....x_n\) 使得 \(a_1*x_1,a_2*x_2,a_3*x_3....a_n*x_n = g (g = gcd(a_1,a_2,..a_n))\)
如果 \(x_1\) != 0 ,将\(x_1,x_2,x_3....x_n\) 减去\(x_1\) 即可
code:
const int maxn = 2e5 + 10;
ll a[maxn];
int n,m;
void solve() {
ll k;
cin >> n >> k;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
ll d = 0;
for(int i = 1; i < n; i++) {
d = __gcd(d,abs(a[i]-a[n]));
}
if((k-a[n]) % d == 0) cout << "YES" << "\n";
else cout << "NO" << "\n";
}
标签:Nezzar,gcd,int,1000000000000000000,黑板,CF1477A,Board,YES,ll 来源: https://www.cnblogs.com/ztns/p/14529321.html