题目链接
http://codeforces.com/contest/687/problem/B
思路
cf题解上有证明:有解的充要条件是
k|lcm(c1,c2,...,cn)
那么只需要求得
lcm(c1,c2,...,cn)即可
首先利用素数筛法,得到所有数的一个质因子,然后进行因式分解,最后判断k能够整除
lcm(c1,c2,...,cn)
即可(k的所有质因子
lcm(c1,c2,...,cn)
里面都应该有)
代码
#include <bits/stdc++.h>
using namespace std;
inline int in() {int x; scanf("%d", &x); return x;}
#define pr(x) {cout << #x << ' ' << x << endl;}
#define LL long long
const int maxn = 1000000 + 5;
int isP[maxn], cntP[maxn];
map<int, int> mm;
int main() {
int n = in(), k = in();
for (int i = 2; i < maxn; i++) {
if (!isP[i])
for (int j = i; j < maxn; j += i) {
isP[j] = i;
}
}
for (int i = 0; i < n; i++) {
int x = in();
while (x > 1) {
int p = isP[x];
int cnt = 0;
while (x % p == 0) {
cnt++;
x /= p;
}
cntP[p] = max(cnt, cntP[p]);
}
}
bool flag = true;
while (k > 1) {
int t = isP[k];
flag &= (cntP[t] > 0);
cntP[t]--;
k /= t;
}
cout << (flag ? "Yes\n" : "No\n");
return 0;
}