結果
| 問題 |
No.3250 最小公倍数
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2025-08-29 23:36:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,748 bytes |
| コンパイル時間 | 2,430 ms |
| コンパイル使用メモリ | 208,576 KB |
| 実行使用メモリ | 285,124 KB |
| 最終ジャッジ日時 | 2025-10-16 16:45:00 |
| 合計ジャッジ時間 | 27,236 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 1 WA * 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;
vector<ll> mul[1<<20];
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) {
(ret[cur]*=b)%=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) {
mul[i].push_back(i);
while(mul[i].back()*i<=1<<20) {
mul[i].push_back(mul[i].back()*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;
}
kmjp