题目:
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
原题链接:http://codeforces.com/gym/101341/problem/D
题意:输入两个数据分别代表第二行数据数量和总距离
解题思路:给出 N 个数,终点 M。 问从 0 开始每次移动 N 个数中的一个距离,是否能达到 M
求出第二行数据的最大公约数即可,与N比较能否整除
要考虑如果所有的数都比M大时直接特判NO
AC代码:
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x,long long y){
return y==0?x:gcd(y,x%y);
}
int main()
{
long long n,m;
scanf("%lld%lld",&n,&m);
long long x,ans;
scanf("%lld",&ans);
for(int i=1;i<n;i++){
scanf("%lld",&x);
ans=gcd(ans,x);
}
if(m==0) puts("YES");
else{
if(m%ans==0) puts("YES");
else puts("NO");
}
}