結果

問題 No.368 LCM of K-products
ユーザー m_tsubasam_tsubasa
提出日時 2020-07-28 22:40:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 2,633 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 212,240 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 06:52:07
合計ジャッジ時間 4,837 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
4,376 KB
testcase_01 AC 96 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 31 ms
4,376 KB
testcase_04 AC 9 ms
4,380 KB
testcase_05 AC 340 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 21 ms
4,380 KB
testcase_14 AC 35 ms
4,376 KB
testcase_15 AC 38 ms
4,376 KB
testcase_16 AC 31 ms
4,380 KB
testcase_17 AC 29 ms
4,380 KB
testcase_18 AC 39 ms
4,380 KB
testcase_19 AC 11 ms
4,380 KB
testcase_20 AC 28 ms
4,376 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 37 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 16 ms
4,380 KB
testcase_34 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

int n, k;
vector<int> a;
map<int, vector<int>> mp;

int main() {
  cin >> n >> k;
  a.resize(n);
  for (auto &p : a) {
    cin >> p;
    long long x = p;
    for (int long long i = 2; i * i <= x; ++i) {
      int cnt = 0;
      while (x % i == 0) ++cnt, x /= i;
      if (cnt) mp[i].push_back(cnt);
    }
    if (x != 1) mp[x].push_back(1);
  }
  ModInt<> res = 1;
  for (auto p : mp) {
    vector<int> v = p.second;
    sort(v.begin(), v.end(), greater<int>());
    int len = min(k, (int)v.size()), cnt = 0;
    for (int i = 0; i < len; ++i) cnt += v[i];
    res *= ModInt<>(p.first).pow(cnt);
  }
  cout << res << endl;
  return 0;
}
0