題目:
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
題意:輸入兩個(gè)數(shù)據(jù)分別代表第二行數(shù)據(jù)數(shù)量和總距離
解題思路:給出 N 個(gè)數(shù)闰歪,終點(diǎn) M。 問從 0 開始每次移動(dòng) N 個(gè)數(shù)中的一個(gè)距離蓖墅,是否能達(dá)到 M
求出第二行數(shù)據(jù)的最大公約數(shù)即可库倘,與N比較能否整除
要考慮如果所有的數(shù)都比M大時(shí)直接特判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");
}
}