結果

問題 No.368 LCM of K-products
ユーザー tatsukawatatsukawa
提出日時 2016-05-25 16:53:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 3,367 bytes
コンパイル時間 1,916 ms
コンパイル使用メモリ 175,948 KB
実行使用メモリ 125,176 KB
最終ジャッジ日時 2023-10-23 21:16:45
合計ジャッジ時間 6,951 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
125,176 KB
testcase_01 AC 103 ms
125,176 KB
testcase_02 AC 98 ms
125,120 KB
testcase_03 AC 99 ms
125,176 KB
testcase_04 AC 102 ms
125,176 KB
testcase_05 AC 119 ms
125,176 KB
testcase_06 AC 97 ms
125,176 KB
testcase_07 AC 98 ms
125,176 KB
testcase_08 AC 99 ms
125,176 KB
testcase_09 AC 96 ms
125,176 KB
testcase_10 AC 97 ms
125,176 KB
testcase_11 AC 97 ms
125,176 KB
testcase_12 AC 98 ms
125,176 KB
testcase_13 AC 104 ms
125,176 KB
testcase_14 AC 110 ms
125,176 KB
testcase_15 AC 111 ms
125,176 KB
testcase_16 AC 109 ms
125,176 KB
testcase_17 AC 107 ms
125,176 KB
testcase_18 AC 112 ms
125,176 KB
testcase_19 AC 101 ms
125,176 KB
testcase_20 AC 107 ms
125,176 KB
testcase_21 AC 100 ms
125,176 KB
testcase_22 AC 112 ms
125,176 KB
testcase_23 AC 97 ms
125,176 KB
testcase_24 AC 98 ms
125,176 KB
testcase_25 AC 96 ms
125,176 KB
testcase_26 AC 97 ms
125,176 KB
testcase_27 AC 97 ms
125,176 KB
testcase_28 AC 97 ms
125,176 KB
testcase_29 AC 98 ms
125,176 KB
testcase_30 AC 98 ms
125,176 KB
testcase_31 AC 100 ms
125,176 KB
testcase_32 AC 98 ms
125,176 KB
testcase_33 AC 104 ms
125,176 KB
testcase_34 AC 99 ms
125,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll=int64_t;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define RER(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
template<typename T> void input(T &x, size_t n) { for(int i = 0; i < n; i++) { cin >> x[i]; } }
//=====debug======
void* enabler;
#define debug(...) cout << __VA_ARGS__ << endl;
template<typename T> class has_begin_and_end { private: template<typename U> static auto check( U v ) -> decltype( v.begin(), v.end(), std::true_type() ); static auto check( ... ) -> decltype( std::false_type() ); public: typedef decltype( check( std::declval<T>() ) ) type; static bool const value = type::value; };
template<typename T> class has_top_and_pop { private: template<typename U> static auto check( U v ) -> decltype( v.empty(), v.top(), v.pop(), std::true_type() ); static auto check( ... ) -> decltype( std::false_type() ); public: typedef decltype( check( std::declval<T>() ) ) type; static bool const value = type::value; }; template<typename T>
class has_front_and_pop { private: template<typename U> static auto check( U v ) -> decltype( v.empty(), v.front(), v.pop(), std::true_type() ); static auto check( ... ) -> decltype( std::false_type() ); public: typedef decltype( check( std::declval<T>() ) ) type; static bool const value = type::value; }; 
template<class T, typename std::enable_if<has_begin_and_end<T>::value>::type*& = enabler> void output(const T& val){ auto it = val.begin(); cout << (*it++); for(; it != val.end(); ++it) cout << ' ' << (*it); cout << endl; }
template<class T, typename std::enable_if<has_top_and_pop<T>::value>::type*& = enabler> void output(T val){ while(!val.empty()){ debug(val.top()); val.pop(); } }
template<class T, typename std::enable_if<has_front_and_pop<T>::value>::type*& = enabler> void output(T val){ while(!val.empty()){ debug(val.front()); val.pop(); } }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& v) { os << "(" <<  v.first <<  ", " << v.second << ")"; return os; } 

const int MAX = 1e9;
const int MOD = 1e9+7;
vector<int> prime;

void make() {
    vector<bool> used(MAX);
    used[0] = used[1] = true;
    for(int i = 2; i*i < MAX; i++) {
        if(used[i]) continue;
        prime.emplace_back(i);
        for(int j = i+i; j < 1e7; j += i) {
            used[j] = true;
        }
    }
}

int main() {
    make();
    int n, k;
    ll res = 1LL;
    cin >> n >> k;
    vector<int> a(n);
    input(a, n);
    vector<int> x[100000];
    REP(i, n) {
        int k = a[i];
        REP(j, prime.size()) {
            int count = 0;
            if(k == 1) break;
            while(k%prime[j]==0) {
                k/=prime[j];
                count++;
            }
            if(prime.size() - 1 == j) {
                if(k > 1) {
                    prime.emplace_back(k);
                }
            }
            if(count == 0) continue;
            x[j].emplace_back(count);
        }
    }

    REP(i, prime.size()){ 
        sort(x[i].begin(), x[i].end(), greater<int>());
        int l = min(k, (int)(x[i].size()));
        REP(j, l) {
            REP(k, x[i][j]) {
                res *= prime[i];
                res %= MOD;
            }
//            cout << prime[i] << ' ' << x[i][j] << endl;
            //res *= ((ll)pow(prime[i], x[i][j]) % MOD);
        }
    }

    cout << res << endl;
}
0