§ Description
Link.
distinct integers are written on the board. Nezzar can perform the following operation multiple times.
- Select two integers (not necessarily distinct) on the board, and write down . Note that you don't remove selected numbers.
Now, Nezzar wonders if it is possible to have his favorite number on the board after applying above operation multiple times.
§ Solution
Let us onsider how to express all the number we can express. Since , the expression is . Since , the expression could be written as , which means the answer exists where has solutions. Beout's identity works.
#include<bits/stdc++.h>
typedef long long ll;
#define sf(x) scanf("%d",&x)
#define ssf(x) scanf("%lld",&x)
int main()
{
int T,n;
ll k;
sf(T);
while(T-->0)
{
sf(n),ssf(k);
ll g=0,x1,x;
ssf(x1);
for(int i=2;i<=n;++i) ssf(x),g=std::__gcd(x-x1,g);
puts((k-x1)%g==0?"YES":"NO");
}
return 0;
}