D. Jumps
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output
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
Copy
3 17
3 5 4
Output
Copy
YES
Input
Copy
4 5
10 20 30 40
Output
Copy
NO
思路:他能到达的位置一定是最小步数的的整数倍,两个数能到达的最小步数是两个数的最大公约数。
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll x;
ll a[200010];
int main()
{
int n,i;
ll mi;
scanf("%d %lld",&n,&x);
scanf("%lld",&a[1]);
mi=a[1];//gcd表示能走的最小步数,如果能到达,一定是最小步数的倍数.
for(i=2;i<=n;i++)
{
scanf("%lld",&a[i]);
mi=__gcd(mi,a[i]);
}
if(x%mi==0)
printf("YES\n");
else
printf("NO\n");
return 0;
}