結果

問題 No.2497 GCD of LCMs
ユーザー Kude
提出日時 2023-10-06 23:56:32
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 2,172 bytes
コンパイル時間 3,620 ms
コンパイル使用メモリ 285,156 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-26 17:25:43
合計ジャッジ時間 4,443 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;
template<class T>
vector<pair<T, int>> factorize(T x) {
vector<pair<T, int>> res;
for(T p = 2; p * p <= x; p++) {
int cnt = 0;
while(x % p == 0) x /= p, cnt++;
if (cnt) res.emplace_back(p, cnt);
}
if (x > 1) res.emplace_back(x, 1);
return res;
}
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
VI a(n);
rep(i, n) cin >> a[i];
VVI to(n);
rep(_, m) {
int u, v;
cin >> u >> v;
u--, v--;
to[u].emplace_back(v);
to[v].emplace_back(u);
}
VI ps;
rep(i, n) {
for (auto [p, _] : factorize(a[i])) {
ps.emplace_back(p);
}
}
sort(all(ps));
ps.erase(unique(all(ps)), ps.end());
vector<mint> ans(n, 1);
VI c(n);
constexpr int INF = 1001001001;
VI vs[30];
for (int p : ps) {
rep(i, n) {
int cnt = 0;
int now = a[i];
while(now % p == 0) now /= p, cnt++;
c[i] = cnt;
}
VI dist(n, INF);
dist[0] = c[0];
vs[c[0]].emplace_back(0);
mint pd = 1;
rep(d, 30) {
while(vs[d].size()) {
int u = vs[d].back(); vs[d].pop_back();
if (dist[u] != d) continue;
ans[u] *= pd;
for (int v : to[u]) {
int nd = max(d, c[v]);
if (nd < dist[v]) {
dist[v] = nd;
vs[nd].emplace_back(v);
}
}
}
pd *= p;
}
}
for (mint x : ans) cout << x.val() << '\n';
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0