結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー kuhakukuhaku
提出日時 2021-07-21 22:07:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 5,431 bytes
コンパイル時間 2,466 ms
コンパイル使用メモリ 221,444 KB
実行使用メモリ 11,936 KB
最終ジャッジ日時 2023-09-24 17:49:22
合計ジャッジ時間 13,088 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 208 ms
9,940 KB
testcase_01 AC 556 ms
9,492 KB
testcase_02 AC 581 ms
9,532 KB
testcase_03 AC 580 ms
9,452 KB
testcase_04 AC 580 ms
9,688 KB
testcase_05 AC 578 ms
9,608 KB
testcase_06 AC 581 ms
9,684 KB
testcase_07 AC 579 ms
9,588 KB
testcase_08 AC 582 ms
9,452 KB
testcase_09 AC 582 ms
9,552 KB
testcase_10 AC 306 ms
9,516 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define FORR(i, m, n) for(int i = (m)-1; i >= (n); --i)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FOR(i, 1, n+1)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n+1, 1)
#define all(s) (s).begin(), (s).end()
template <class T, class U>
bool chmax(T &a, const U b) { return a < b ? a = b, true : false; }
template <class T, class U>
bool chmin(T &a, const U b) { return b < a ? a = b, true : false; }
template <class T>
istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is>>i; return is; }
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (auto it=v.begin(); it!=v.end(); ++it) { os<<(it==v.begin()?"":" ")<<*it; } return os;
}
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    if constexpr(sizeof...(tail)==0) cout<<head<<'\n'; else cout<<head<<' ',co(forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    if constexpr(sizeof...(tail)==0) cerr<<head<<'\n'; else cerr<<head<<' ',ce(forward<Tail>(tail)...);
}
template<typename T, typename... Args>
auto make_vector(T x, int arg, Args ...args) {
    if constexpr(sizeof...(args)==0) return vector<T>(arg, x); else return vector(arg,make_vector<T>(x, args...));
}
void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); }
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr int MOD = 1000000007;
constexpr int MOD_N = 998244353;
constexpr double EPS = 1e-7;
const double PI = acos(-1);

struct prime_number {
    const int sz = 1 << 22;
    bitset<1 << 22> is_not_prime;
    vector<int> data;

    prime_number() { init(); }

    void init() {
        is_not_prime[0] = is_not_prime[1] = true;
        for (int i = 2; i < sz; ++i) {
            if (!is_not_prime[i]) {
                data.emplace_back(i);
                if ((int64_t)i * i >= sz) continue;
                for (int j = i * i; j < sz; j += i) {
                    is_not_prime[j] = true;
                }
            }
        }
    }

    bool is_prime(int64_t n) {
        assert(n >= 0);
        if (n < sz) return !is_not_prime[n];
        for (auto i : data) {
            if ((int64_t)i * i > n) break;
            if (n % i == 0) return false;
        }
        return true;
    }

    vector<int> prime_numbers(int x) {
        vector<int> res;
        for (int i = 2; i <= x; ++i) {
            if (is_prime(i)) res.emplace_back(i);
        }
        return res;
    }

    // 素因数分解
    template <class T>
    vector<pair<T, int>> prime_factorization(T x) {
        if (x == 1) return vector<pair<T, int>>(1, {1, 1});
        vector<pair<T, int>> res;
        for (auto i : data) {
            int cnt = 0;
            for (; x % i == 0; x /= i) cnt++;
            if (cnt) res.emplace_back(i, cnt);
            if ((int64_t)i * i > x) break;
        }
        if (x != 1) res.emplace_back(x, 1);
        return res;
    }

    // 約数列挙
    template <class T>
    vector<T> divisors(T x) {
        auto v = prime_factorization(x);
        vector<T> res, a, b, cp;
        res.emplace_back(1);
        for (auto p : v) {
            int n = res.size();
            cp.resize(n);
            copy(res.begin(), res.end(), cp.begin());
            a.resize(n);
            T t = 1;
            for (int k = 0; k < p.second; ++k) {
                t *= p.first;
                for (int i = 0; i < n; ++i) a[i] = cp[i] * t;
                merge(res.begin(), res.end(), a.begin(), a.end(),
                      back_inserter(b));
                swap(res, b);
                b.clear();
            }
        }
        return res;
    }

    // 因数分解列挙
    template <class T>
    vector<vector<T>> factorization(T x) {
        vector<vector<T>> res;
        auto f = [&](auto self, vector<T> v, T a) -> void {
            if (a == 1) res.emplace_back(v);
            for (auto i : divisors(a)) {
                if (i == 1 || (!v.empty() && v.back() > i)) continue;
                v.emplace_back(i);
                self(self, v, a / i);
                v.pop_back();
            }
        };
        f(f, vector<T>(), x);
        return res;
    }
};
prime_number pn;

// clang-format on

int main(void) {
    int t;
    cin >> t;

    vector<vector<pair<ll, int>>> vv;
    vv.resize(1000);

    FOR(i, 2, 1000) {
        vv[i] = pn.prime_factorization((ll)i);
    }
    unordered_map<ll, ll> memo;
    rep(_, t) {
        ll x;
        cin >> x;
        if (memo.count(x)) {
            co(memo[x]);
            continue;
        }
        auto v = pn.prime_factorization(x);
        unordered_map<ll, int> mp;
        ll s = 1;
        for (auto p : v) {
            mp[p.first] = p.second;
            s *= p.second + 1;
        }

        FOR(i, 2, 1000) {
            auto u = vv[i];
            auto np = mp;
            for (auto p : u) {
                np[p.first] += p.second;
            }
            ll t = 1;
            for (auto p : np) {
                t *= p.second + 1;
            }

            if (s * 2 == t) {
                co(x * i);
                memo[x] = x * i;
                break;
            }
        }
    }

    return 0;
}
0