結果
| 問題 | No.3250 最小公倍数 | 
| コンテスト | |
| ユーザー |  nururi | 
| 提出日時 | 2025-09-18 19:35:58 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                MLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,243 bytes | 
| コンパイル時間 | 3,563 ms | 
| コンパイル使用メモリ | 288,544 KB | 
| 実行使用メモリ | 822,156 KB | 
| 最終ジャッジ日時 | 2025-10-16 17:09:42 | 
| 合計ジャッジ時間 | 11,306 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | -- * 1 | 
| other | MLE * 1 -- * 21 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
const long mod = 998244353;
bool seen[N];
vector<int> path[N];
unordered_map<long, int> mp[N], ans[N];
int dfs(int cur){
  seen[cur] = true;
  
  vector<int> childs;
  for(auto next:path[cur]){
    if(!seen[next]) childs.push_back(dfs(next));
  }
  
  for(auto i:childs){
    for(auto x:ans[i]){
      ans[cur][x.first] = max(ans[cur][x.first], x.second);
    }
  }
  
  return cur;
}
int main(){
  int n;
  cin >> n;
  
  vector<int> primes;
  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) primes.push_back(i);
  }
  
  for(int i=0; i<n; i++){
    long a;
    cin >> a;
    for(auto p:primes){
      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;
  }
}
            
            
            
        