結果
問題 |
No.3250 最小公倍数
|
ユーザー |
|
提出日時 | 2025-08-04 21:59:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,407 bytes |
コンパイル時間 | 1,780 ms |
コンパイル使用メモリ | 208,376 KB |
実行使用メモリ | 304,108 KB |
最終ジャッジ日時 | 2025-08-29 20:51:38 |
合計ジャッジ時間 | 29,981 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 17 TLE * 1 -- * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:44:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:45:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:49:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 49 | scanf("%d%d", &u, &v); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 998244353; const int N = 500005; const int INF = 0x3f3f3f3f; ll a[N]; map<ll, ll> mp[N], m1, m2; ll powmod(ll x, ll y, ll mod) { ll res = 1; while (y) { if (y & 1) res = res * x % mod; y >>= 1; x = x * x % mod; } return res; } void get_factor(ll n, map<ll, ll> &mp) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) { n /= i; mp[i]++; } } } if (n != 1) mp[n]++; } vector<int> G[N]; int fa[N]; void dfs(int u) { for (auto v : G[u]) { if (v == fa[u]) continue; fa[v] = u; dfs(v); m1 = mp[u], m2 = mp[v]; if ((int)m1.size() > (int)m2.size()) swap(m1, m2); for (auto [x, y] : m2) m1[x] = max(m1[x], y); mp[u] = m1; } } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n; i++) get_factor(a[i], mp[i]); for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } dfs(1); for (int i = 1; i <= n; i++) { ll res = 1; for (auto [x, y] : mp[i]) res = res * powmod(x, 1ll * y, mod) % mod; printf("%lld\n", res); } return 0; }