必威体育Betway必威体育官网
当前位置:首页 > IT技术

Gym - 101341D

时间:2019-09-07 06:42:12来源:IT技术作者:seo实验室小编阅读:80次「手机版」
 

gym

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

思路:

即求解方程组,且必须有整数解;

考虑两个的情况,即 ax+by=c;

此时c % gcd(a,b)才有解;

同理推广到多元即可;

#include<iOStream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 200005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;
#define pi acos(-1.0)



ll quickpow(ll a, ll b) {
    ll ans = 1;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}

int a[maxn];

int main() {
    int n, k;
    cin >> n >> k;
    int i, j;
    if (n == 1) {
        int x;
        cin >> x;
        if (k%x != 0) {
            cout << "NO" << endl;
        }
        else cout << "YES" << endl;
    }
    else {
        cin >> a[0] >> a[1];
        int Gcd = gcd(a[0], a[1]);
        for (i = 2; i < n; i++) {
            cin >> a[i];
            Gcd = gcd(Gcd, a[i]);
        }
        if (k%Gcd != 0)cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}

相关阅读

Adjoin the Networks Gym - 100781A

http://codeforces.com/gym/100781/attachments 给出一个森林 问将图连通后最小的树直径 对于所有连通块都求出直径 若只有一个连

分享到:

栏目导航

推荐阅读

热门阅读