結果
| 問題 |
No.3250 最小公倍数
|
| コンテスト | |
| ユーザー |
nururi
|
| 提出日時 | 2025-09-18 22:23:23 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,267 bytes |
| コンパイル時間 | 3,610 ms |
| コンパイル使用メモリ | 288,260 KB |
| 実行使用メモリ | 829,860 KB |
| 最終ジャッジ日時 | 2025-10-16 17:09:54 |
| 合計ジャッジ時間 | 11,396 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | MLE * 1 -- * 21 |
ソースコード
#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;
}
}
nururi