結果

問題 No.2682 Visible Divisible
ユーザー KKT89KKT89
提出日時 2024-03-20 21:50:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 6,968 bytes
コンパイル時間 3,326 ms
コンパイル使用メモリ 229,872 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-20 21:50:36
合計ジャッジ時間 5,764 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
6,548 KB
testcase_01 AC 106 ms
6,548 KB
testcase_02 AC 106 ms
6,548 KB
testcase_03 AC 105 ms
6,548 KB
testcase_04 AC 86 ms
6,548 KB
testcase_05 AC 86 ms
6,548 KB
testcase_06 AC 85 ms
6,548 KB
testcase_07 AC 84 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 92 ms
6,548 KB
testcase_12 AC 95 ms
6,548 KB
testcase_13 AC 93 ms
6,548 KB
testcase_14 AC 102 ms
6,548 KB
testcase_15 AC 92 ms
6,548 KB
testcase_16 AC 89 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

template <int mod>
struct static_modint {
    using mint = static_modint;
    int x;

    static_modint() : x(0) {}
    static_modint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    mint& operator+=(const mint& rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        x = (int) (1LL * x * rhs.x % mod);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }

    mint pow(long long n) const {
        mint _x = *this, r = 1;
        while (n) {
            if (n & 1) r *= _x;
            _x *= _x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const { return pow(mod - 2); }

    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs.x == rhs.x;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs.x != rhs.x;
    }

    friend ostream &operator<<(ostream &os, const mint &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, mint &a) {
        int64_t t; is >> t;
        a = static_modint<mod>(t);
        return (is);
    }
};

const unsigned int mod = 998244353;
using modint = static_modint<mod>;
modint mod_pow(ll n, ll x) { return modint(n).pow(x); }
modint mod_pow(modint n, ll x) { return n.pow(x); }

// verify:https://www.acmicpc.net/problem/4149
namespace factorize{
    using u64 = uint64_t;
    using u128 = __uint128_t;
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

    u64 binary_gcd(u64 a, u64 b) {
        if (a == 0) return b;
        if (b == 0) return a;
        const int n = __builtin_ctzll(a | b);
        a >>= __builtin_ctzll(a);
        while (b > 0) {
            b >>= __builtin_ctzll(b);
            if (a > b) std::swap(a, b);
            b -= a;
        }
        return a << n;
    }

    u128 pow (u128 a, u64 n, u128 mod) {
        u128 res = 1;
        if (a >= mod) a %= mod;
        while (n > 0) {
            if (n & 1) {
                res *= a;
                if (res >= mod) res %= mod;
            }
            a *= a;
            if (a >= mod) a %= mod;
            n >>= 1;
        }
        return res;
    }

    bool miller_rabin (u64 n, vector<u64> v) {
        u64 d = n-1;
        while (~d & 1) d >>= 1;
        for (u64 a:v) {
            if (n <= a) break;
            u64 t = d;
            u128 y = pow(a, t, n);
            while (t != n-1 and y != 1 and y != n-1) {
                y *= y; if(y >= n) y %= n;
                t *= 2;
            }
            if (y != n-1 and t % 2 == 0) return false;
        }
        return true;
    }

    bool is_prime (u64 n) {
        if (n <= 1) return false;
        if (~n & 1) return (n == 2);
        if (n < (1LL << 30)) {
            return miller_rabin(n, {2, 7, 61});
        }
        else {
            return miller_rabin(n, {2, 325, 9375, 28178, 450775, 9780504, 1795265022});
        }
    }

    template <typename T>
    T pollard_rho (T n) {
        if (~n & 1) return 2;
        if (is_prime(n)) return n;

        static u128 x,y,c,d;
        auto f = [&](u128 x) {return (x * x % n + c) % n;};
        auto rnd_ = [&](T l, T r) {return rng() % (r - l + 1) + l;};

        x = rnd_(2, n);
        y = x;
        c = rnd_(1, n);
        d = 1;

        while (d == 1) {
            x = f(x);
            y = f(y); y = f(y);
            d = binary_gcd((x > y ? x-y : y-x), n);
            if ((T)d == n) {
                return pollard_rho(n);
            }
        }
        if (is_prime(d)) {
            return d;
        }
        else {
            return pollard_rho(d);
        }
    }

    template <typename T>
    vector<T> prime_factor (T n) {
        vector<T> res;
        for (T i = 2; i*i <= n;) {
            while (n % i == 0) {
                n /= i;
                res.emplace_back(i);
            }
            i += 1 + (~n & 1);
            if (i >= 101 and n >= (1<<20)) {
                while (n > 1) {
                    auto p = pollard_rho(n);
                    while (n % p == 0) {
                        n /= p;
                        res.emplace_back(p);
                    }
                }
                break;
            }
        }
        if (n > 1) res.emplace_back(n);
        sort(res.begin(), res.end());
        return res;
    }

    template <typename T>
    map<T, int> factor_count (T n) {
        map<T, int> mp;
        for (auto &x : prime_factor(n)) mp[x]++;
        return mp;
    }

    template <typename T>
    vector<T> divisors(T n) {
        if (n == 0) return {};
        vector<pair<T, int>> v;
        for(auto &p : factor_count(n)) v.push_back(p);
        vector<T> res;
        auto f = [&](auto self, int i, T x) -> void {
            if (i == (int)v.size()) {
                res.push_back(x);
                return;
            }
            for (int j = 0; j <= v[i].second; ++j) {
                self(self, i + 1, x);
                if (j+1 <= v[i].second) {
                    x *= v[i].first;
                }
            }
        };
        f(f, 0, 1);
        sort(res.begin(), res.end());
        return res;
    }

} // namespace factorize

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll k; cin >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] = gcd(a[i], k);
    }
    auto f = factorize::factor_count(k);
    map<ll, int> mp;
    for (auto &p : f) {
        ll d = p.first;
        int mx = 0;
        for (int i = 0; i < n; ++i) {
            int cnt = 0;
            while (a[i]%d == 0) {
                cnt += 1;
                a[i] /= d;
            }
            mx = max(mx, cnt);
        }
        if (mx < p.second) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}
0