結果

問題 No.368 LCM of K-products
ユーザー shora_kujira16shora_kujira16
提出日時 2016-04-29 23:23:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 1,504 bytes
コンパイル時間 1,970 ms
コンパイル使用メモリ 188,648 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 21:10:43
合計ジャッジ時間 4,971 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
4,348 KB
testcase_01 AC 233 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 72 ms
4,348 KB
testcase_04 AC 112 ms
4,348 KB
testcase_05 AC 371 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 59 ms
4,348 KB
testcase_14 AC 119 ms
4,348 KB
testcase_15 AC 142 ms
4,348 KB
testcase_16 AC 111 ms
4,348 KB
testcase_17 AC 87 ms
4,348 KB
testcase_18 AC 149 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 79 ms
4,348 KB
testcase_21 AC 12 ms
4,348 KB
testcase_22 AC 139 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 33 ms
4,348 KB
testcase_34 AC 15 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl

constexpr int MOD = 1000000007;

int pow_mod(int x, int y) {
  int res = 1;
  for(; y > 0; y >>= 1, (x *= x) %= MOD) {
    if(y & 1) (res *= x) %= MOD;
  }
  return res;
}

template<class T, class U>
U get_or_else(const std::map<T, U> m, const T key, const U def) {
  auto it = m.find(key);
  if(it == m.end()) {
    return def;
  }
  else {
    return it->second;
  }
}

signed main() {
  int N, K; cin >> N >> K;
  vector<int> A(N);
  REP(i,N) cin >> A[i];
  vector<map<int, int>> factors(N);
  vector<int> allfactors;
  REP(i,N) {
    int num = A[i];
    while(num > 1) {
      bool div = false;
      for(int k = 2; k * k <= num; ++k) {
        if(num % k == 0) {
          factors[i][k]++;
          allfactors.push_back(k);
          num /= k;
          div = true;
          break;
        }
      }
      if(!div) {
        factors[i][num]++;
        allfactors.push_back(num);
        break;
      }
    }
  }
  sort(allfactors.begin(), allfactors.end());
  allfactors.erase(unique(allfactors.begin(), allfactors.end()), allfactors.end());
  int ans = 1;
  for(int fact : allfactors) {
    vector<int> cnt;
    REP(i,N) {
      cnt.push_back(get_or_else(factors[i], fact, 0LL));
    }
    sort(cnt.rbegin(), cnt.rend());
    REP(j,K) {
      ans *= pow_mod(fact, cnt[j]);
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
0