Codeforces687B-Remainders Game(数论)

题目链接

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值