結果

問題 No.368 LCM of K-products
ユーザー siguma323siguma323
提出日時 2016-05-03 22:54:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,769 bytes
コンパイル時間 1,303 ms
コンパイル使用メモリ 108,880 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2024-04-15 11:05:55
合計ジャッジ時間 5,611 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 134 ms
19,840 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 345 ms
11,392 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
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 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 82 ms
6,944 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <utility>
#include <cmath>
#include <map>
#include <unordered_map>
#include <functional>
#include <fstream>
using namespace std;

using ull = unsigned long long;

const int MOD = static_cast<int>(1e9+7);

ull fast_pow(ull num,ull n)
{
    ull x = num;
    ull result = 1;
    while(n)
    {
        if(n & 1) result = (result * x) % MOD;
        x *= x % MOD;
        n = n >> 1;
    }

    return result;
}

int main()
{
    ull n,k;
    cin >> n >> k;

    vector<ull> a(n);
    map<ull,vector<ull>> dic;

    for(int i =0; i < n; ++i)
    {
        cin >> a.at(i);
        ull tmp = a.at(i);

        int j = 2;
        while(j*j <= a.at(i))
        {
            if(tmp % j ==0)
            {
                vector<ull> t(n,0);
                tmp /= j;
                if(dic.find(j) != dic.end())
                {
                    dic.at(j).at(i) +=1;
                }
                else
                {
                    dic.emplace(j,t);
                    dic.at(j).at(i) = 1;
                }
            }
            else
            {
                ++j;
            }
        }

        vector<ull> t(n,0);
        if(dic.find(tmp) != dic.end())
        {
            dic.at(tmp).at(i) +=1;
        }
        else
        {
            dic.emplace(tmp,t);
            dic.at(tmp).at(i) = 1;
        }
    }

    ull sum = 1;
    for(auto&& x : dic)
    {
        sort(x.second.begin(),x.second.end(),greater<ull>());

        ull count = 0;
        for(int i =0; i < k ; ++i)
        {
            count += x.second.at(i);
        }
        sum = (sum*fast_pow(x.first,count)) % MOD;
    }

    cout << sum << endl;
}
0