結果
| 問題 |
No.3250 最小公倍数
|
| コンテスト | |
| ユーザー |
nururi
|
| 提出日時 | 2025-09-18 18:56:00 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,031 bytes |
| コンパイル時間 | 3,614 ms |
| コンパイル使用メモリ | 289,492 KB |
| 実行使用メモリ | 504,776 KB |
| 最終ジャッジ日時 | 2025-10-16 17:09:20 |
| 合計ジャッジ時間 | 11,109 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | TLE * 1 -- * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
const long mod = 998244353;
bool seen[N];
vector<int> path[N];
map<long, int> mp[N], ans[N];
map<long, int> dfs(int cur){
seen[cur] = true;
vector<map<long, int>> child;
for(auto next:path[cur]){
if(!seen[next]) child.push_back(dfs(next));
}
for(auto x:child){
for(auto y:x){
ans[cur][y.first] = max(ans[cur][y.first], y.second);
}
}
return ans[cur];
}
int main(){
int n;
cin >> n;
for(int i=0; i<n; i++){
long a;
cin >> a;
for(long p=2; p*p<=a; p++){
while(a%p==0){
mp[i][p]++;
a /= p;
}
}
if(a>1) mp[i][a]++;
}
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);
}
for(int i=0; i<n; i++) ans[i] = mp[i];
dfs(0);
for(int i=0; i<n; i++){
long out = 1;
for(auto x:ans[i]){
while(x.second--) out = out * x.first % mod;
}
cout << out << endl;
}
}
nururi