結果

問題 No.368 LCM of K-products
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-04-04 06:01:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,760 bytes
コンパイル時間 1,422 ms
コンパイル使用メモリ 176,468 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 11:08:44
合計ジャッジ時間 3,370 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1e9 + 7;

map<ll, ll> primeFactorize(ll n) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n > 1) ++res[n];
    return res;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    // 各素因数について、指数を大きい順に記録
    map<ll, priority_queue<ll> > exponents;
    rep(i, n) {
        auto res = primeFactorize(a[i]);

        // cout << "primeFactorize " << a[i] << ":";
        // for (auto p : res) {
        //     cout << " " << p.first << "^" << p.second;
        // }
        // cout << endl;

        for (auto p : res) {
            exponents[p.first].push(p.second);
        }
    }

    // cout << "Exponents:" << endl;
    // for (auto p : exponents) {
    //     cout << p.first << ": ";
    //     auto que = p.second;
    //     while (!que.empty()) {
    //         auto x = que.top(); que.pop();
    //         cout << " " << x;
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    ll ans = 1;
    for (auto p : exponents) {
        auto x = p.first;
        auto que = p.second;
        ll num = que.top(); que.pop();
        if (!que.empty()) num += que.top(); que.pop();
        ans = ans * ((ll)pow(x, num) % mod) % mod;
    }

    cout << ans << endl;

}
0