Jumps(裴蜀定理)

http://codeforces.com/gym/101341/problem/D

 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

裴蜀定理
 具体步骤就是求gcd,看要组成的数是不是这个gcd的倍数
 
 
 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     long long n, x, xx, data, i;
 8     scanf("%lld %lld", &n, &x);
 9     for(i=0;i<n;i++)
10     {
11         scanf("%lld", &data);
12         if(i==0) xx = data;
13         else xx = __gcd(xx, data);
14     }
15     if(x%xx==0) printf("YES\n");
16     else printf("NO\n");
17     return 0;
18 }

 

 
 
 

转载于:https://www.cnblogs.com/0xiaoyu/p/11559118.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值