题目描述:
A frog lives in a one-dimensional world in the point with the coordinate 0. He needs to get to the point with the coordinate x. For some reason he cannot make jumps of arbitrary length, and can jump only by a1, ..., an in any direction. Is he able to reach x? InputThe first line contains two integers n and x separated by a space (1 ≤ n ≤ 200000, - 109 ≤ x ≤ 109) — the number of variants of jump length and the coordinate of the point to reach.
The second line contains n integers ai separated by spaces (1 ≤ ai ≤ 109) — the lengths of jumps the frog can make.
Output
Output «YES» (without quotes), if the frog can reach the point x, otherwise output «NO» (without quotes).
Examples
Input
3 17
3 5 4
Output
YES
Input
4 5
10 20 30 40
Output
NO
裴蜀定理:
比赛的时候莽过了,感觉此类题目就是和gcd有关,后来知道该题运用了裴蜀定理。
裴蜀定理:裴蜀定理(或贝祖定理)得名于法国数学家艾蒂安·裴蜀,说明了对任何整数a、b和它们的最大公约数d,关于未知数x和y的线性不定方程(称为裴蜀等式):若a,b是整数,且gcd(a,b)=d,那么对于任意的整数x,y,ax+by都一定是d的倍数,特别地,一定存在整数x,y,使ax+by=d成立。
AC代码:
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
return b?gcd(b, a%b):a;
}
int main()
{
int a[200010];
int n,x,f;
cin>>n>>x;
for(int i=0; i<n; i++)
cin>>a[i];
f=a[0];
for(int i=1; i<n; i++)
f=gcd(f,a[i]);
if(abs(x)%f==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}