結果
| 問題 |
No.3250 最小公倍数
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2025-08-29 21:33:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,238 bytes |
| コンパイル時間 | 4,283 ms |
| コンパイル使用メモリ | 259,640 KB |
| 実行使用メモリ | 180,108 KB |
| 最終ジャッジ日時 | 2025-11-09 23:05:34 |
| 合計ジャッジ時間 | 24,996 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 21 TLE * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:55:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
55 | scanf("%d",&a);
| ~~~~~^~~~~~~~~
main.cpp:65:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
65 | scanf("%d %d",&u,&v);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000005
#define Inf64 1000000000000000001LL
mint ans[500005];
map<int,int> mp[500005];
vector<vector<int>> E;
void dfs(int cv,int pv){
vector<int> vs;
rep(i,E[cv].size()){
int to = E[cv][i];
if(to==pv)continue;
dfs(to,cv);
vs.push_back(to);
}
rep(i,vs.size()){
int x = cv,y = vs[i];
if(mp[x].size() < mp[y].size()){
swap(mp[x],mp[y]);
ans[x] = ans[y];
}
for(auto z:mp[y]){
int p = z.first;
int fx = mp[x][p],fy = z.second;
if(fy > fx){
rep(_, fy - fx){
ans[x] *= p;
}
mp[x][p] = fy;
}
}
mp[y].clear();
}
}
int main(){
int n;
cin>>n;
vector<int> ps(1000001);
for(int i=2;i<ps.size();i++){
if(ps[i]!=0)continue;
for(int j=i;j<ps.size();j+=i){
if(ps[j]==0)ps[j] = i;
}
}
rep(i,n){
int a;
scanf("%d",&a);
ans[i] = a;
while(a>1){
mp[i][ps[a]]++;
a /= ps[a];
}
}
E.resize(n);
rep(i,n-1){
int u,v;
scanf("%d %d",&u,&v);
u--,v--;
E[u].push_back(v);
E[v].push_back(u);
}
dfs(0,-1);
rep(i,n){
printf("%d\n",ans[i].val());
}
}
沙耶花