题解:Niton & LCM
Shaoxing_Sun · · 题解
题意
构造一个非空不可重集合
思路
若
接下来,倘若某个元素
也就是说,我们要构造的集合实际上是这样的:
接下来,如果把它们全部拿来做
最后,如果
#include <bits/stdc++.h>
#define IOS std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define lcb(x) ((x) * size - size + 1)
#define rcb(x) ((x) * size)
#define lc(x) x << 1ll
#define rc(x) x << 1ll | 1ll
#define lowbit(x) ((x) & (-x))
#define LEN_LC (tree[lc(i)].r - tree[lc(i)].l + 1)
#define LEN_RC (tree[rc(i)].r - tree[rc(i)].l + 1)
#define LEN (tree[i].r - tree[i].l + 1)
#define int long long
#define ull unsigned long long
#define endl "\n"
const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
template<typename T>inline void read(T &x) {
bool f = 1;
x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = !f;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x = (f ? x : -x);
return;
}
ull n, k;
ull a[N];
void solve() {
std::cin >> n >> k;
rep(i, 1, n) {
std::cin >> a[i];
}
if(k == 1) {
bool flag = false;
rep(i, 1, n) {
if(a[i] == 1) {
flag = true;
break;
}
}
if(flag) {
std::cout << "Yes" << endl;
} else {
std::cout << "No" << endl;
}
return ;
}
ull now = 1;
rep(i, 1, n) {
if(k % a[i] == 0) {
ull gcd = std::__gcd(now, a[i]);
now = now / gcd * a[i];
}
}
if(now == k) {
std::cout << "Yes" << endl;
} else {
std::cout << "No" << endl;
}
}
signed main() {
IOS;
int t; std::cin>> t; while(t--) solve();
return 0;
}
时间复杂度为