結果
問題 |
No.3250 最小公倍数
|
ユーザー |
![]() |
提出日時 | 2025-09-18 22:23:23 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,267 bytes |
コンパイル時間 | 3,060 ms |
コンパイル使用メモリ | 288,304 KB |
実行使用メモリ | 369,124 KB |
最終ジャッジ日時 | 2025-09-18 22:23:54 |
合計ジャッジ時間 | 30,446 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 17 TLE * 2 -- * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int N = 500000; const long mod = 998244353; const long salt = 42; bool seen[N]; vector<int> path[N]; unordered_map<long, int> mp[N]; long ans[N]; int dfs(int cur){ seen[cur] = true; vector<int> child; for(auto next:path[cur]){ if(!seen[next]) child.push_back(dfs(next)); } for(auto i:child){ for(auto x:mp[i]){ int cnt = x.second - mp[cur][x.first]; for(int j=0; j<cnt; j++){ ans[cur] = ans[cur] * (x.first-salt) % mod; } if(cnt>0) mp[cur][x.first] += cnt; } } return cur; } int main(){ int n; cin >> n; vector<int> prime; for(int i=2; i<=1000; i++){ bool is_prime = true; for(int p=2; p*p<=i; p++){ if(i%p == 0){ is_prime = false; break; } } if(is_prime) prime.push_back(i); } for(int i=0; i<n; i++){ long a; cin >> a; ans[i] = a; for(auto p:prime){ while(a%p==0){ mp[i][p+salt]++; a /= p; } } if(a>1) mp[i][a+salt]++; } for(int i=0; i<n-1; i++){ int u, v; cin >> u >> v; u--, v--; path[u].push_back(v); path[v].push_back(u); } dfs(0); for(int i=0; i<n; i++){ cout << ans[i] << endl; } }