結果

問題 No.2497 GCD of LCMs
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-09-03 12:08:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,637 bytes
コンパイル時間 4,618 ms
コンパイル使用メモリ 272,228 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 12:08:55
合計ジャッジ時間 5,590 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 18 ms
4,384 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 21 ms
4,380 KB
testcase_14 AC 12 ms
4,384 KB
testcase_15 AC 12 ms
4,384 KB
testcase_16 AC 22 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define rep(i, a, b) for (int(i) = (a); (i) < (int)(b); (i)++)

using ll = long long;
using mint = modint998244353;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  vector<vector<int>> g(n, vector<int>());
  rep(i, 0, m) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  set<ll> primes;
  rep(i, 0, n) {
    ll x = a[i];
    for (ll d = 2; d * d <= x; d += (d & 1) + 1) {
      if (x % d) continue;
      primes.insert(d);
      while (!(x % d)) x /= d;
    }
    if (x > 1) primes.insert(x);
  }

  ll amax = 0;
  rep(i, 0, n) amax = max(amax, a[i]);

  vector<mint> ans(n, 1);
  for (auto p : primes) {
    vector<int> c(n, 0), d(n, 100);
    rep(i, 0, n) {
      ll x = a[i];
      while (x % p == 0) {
        c[i]++;
        x /= p;
      }
    }
    priority_queue<P> pq;
    pq.push(P(-c[0], 0));
    d[0] = c[0];
    while (!pq.empty()) {
      auto p = pq.top();
      pq.pop();
      int x = p.second;
      if (-p.first > d[x]) continue;
      for (auto y : g[x]) {
        if (d[y] > max(d[x], c[y])) {
          d[y] = max(d[x], c[y]);
          pq.push(P(-d[y], y));
        }
      }
    }
    vector<mint> pow(100);
    pow[0] = 1;
    rep(i, 1, pow.size()) pow[i] = pow[i - 1] * p;
    rep(i, 0, n) ans[i] *= pow[d[i]];
  }

  rep(i, 0, n) cout << ans[i].val() << "\n";
}
0