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?
Input
The 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
思路:这个题当时做,想着多重循环找x,y,z……思路走不通
后来看题解说是gcd觉得太神奇了,还是需要多多训练思维;
以前比赛有一个老鼠的题就是关于辗转相除法,当时用c补了这个题,
这次学了c++的直接gcd;
ac代码
#include <bits/stdc++.h>
using namespace std;
int a[200010];
int main()
{
int n,x,i;
cin>>n>>x;
for(i=1; i<=n; i++)
cin>>a[i];
int g=a[1];
for(i=2; i<=n; i++)
{
g=__gcd(g,a[i]);//辗转相除法
}
if(x%g==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}