101341D型号的健身房器材有哪些特点?

更新于
2026-10-10 02:25:06
1阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计604个文字,预计阅读时间需要3分钟。

101341D型号的健身房器材有哪些特点?

在一个一维世界中,青蛙住在坐标为0的点。它需要到达坐标为x的点。由于某种原因,它不能随意跳跃,只能跳跃固定的距离a1,……,an,且只能朝任意方向跳。

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).

101341D型号的健身房器材有哪些特点?

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; }

本文共计604个文字,预计阅读时间需要3分钟。

101341D型号的健身房器材有哪些特点?

在一个一维世界中,青蛙住在坐标为0的点。它需要到达坐标为x的点。由于某种原因,它不能随意跳跃,只能跳跃固定的距离a1,……,an,且只能朝任意方向跳。

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).

101341D型号的健身房器材有哪些特点?

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; }