結果
問題 |
No.3250 最小公倍数
|
ユーザー |
![]() |
提出日時 | 2025-08-30 00:06:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,682 bytes |
コンパイル時間 | 2,101 ms |
コンパイル使用メモリ | 206,624 KB |
実行使用メモリ | 257,744 KB |
最終ジャッジ日時 | 2025-08-30 00:07:12 |
合計ジャッジ時間 | 24,583 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 TLE * 3 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N; vector<int> E[505050]; unordered_map<int,int> dp[505050]; int V[1<<20]; ll A[1<<19]; ll ret[1<<19]; const ll mo=998244353; void dfs(int cur,int pre) { FORR(e,E[cur]) if(e!=pre) { dfs(e,cur); if(dp[cur].size()<dp[e].size()) { swap(dp[cur],dp[e]); ret[cur]=ret[e]; } FORR2(a,b,dp[e]) { if(dp[cur][a]<b) { if(dp[cur][a]==0) (ret[cur]*=b)%=mo; else (ret[cur]*=b/dp[cur][a])%=mo; dp[cur][a]=b; } } } } void solve() { int i,j,k,l,r,x,y; string s; FOR(i,1<<20) V[i]=i; for(i=2;i<1<<20;i++) if(V[i]==i) { if(i<=1000) for(j=i*i;j<1<<20;j+=i) V[j]=i; } cin>>N; FOR(i,N) { cin>>ret[i]; x=ret[i]; while(x>1) { if(dp[i][V[x]]==0) dp[i][V[x]]=V[x]; else dp[i][V[x]]*=V[x]; x/=V[x]; } } FOR(i,N-1) { cin>>x>>y; E[x-1].push_back(y-1); E[y-1].push_back(x-1); } dfs(0,0); FOR(i,N) cout<<ret[i]<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }