結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー sten_san
提出日時 2021-07-21 22:50:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 2,020 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 193,916 KB
最終ジャッジ日時 2025-01-23 04:53:17
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

int main() {
    constexpr int p[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };

    auto log = [](int x, int y) {
        int ans = 0;
        while (x % y == 0) {
            x /= y;
            ++ans;
        }
        return ans;
    };

    int t; cin >> t;

    while (t--) {
        int64_t x; cin >> x;

        int count[size(p)] = {};
        for (int i = 0; i < size(p); ++i) {
            auto v = x;
            while (v % p[i] == 0) {
                v /= p[i];
                ++count[i];
            }
        }

        int last = 0;
        for (int i = 0; i < size(p); ++i) {
            if (count[i] == 0) {
                last = p[i];
                break;
            }
        }

        int64_t y = x * last;
        for (int i = 2; i < last; ++i) {
            int64_t acc1 = 1;
            int64_t acc2 = 1;
            for (int j = 0; j < size(p); ++j) {
                if (i % p[j] == 0) {
                    acc1 *= count[j] + 1;
                    acc2 *= count[j] + log(i, p[j]) + 1;
                }
            }

            if (acc2 % acc1 == 0 && acc2 / acc1 == 2) {
                chmin(y, x * i);
            }
        }

        cout << y << endl;
    }
}

0