結果
| 問題 |
No.3250 最小公倍数
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2025-08-30 00:49:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,792 bytes |
| コンパイル時間 | 2,209 ms |
| コンパイル使用メモリ | 213,644 KB |
| 実行使用メモリ | 111,412 KB |
| 最終ジャッジ日時 | 2025-10-16 16:50:34 |
| 合計ジャッジ時間 | 9,681 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | TLE * 1 -- * 21 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:56:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
56 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp:58:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | scanf("%d",&x);
| ~~~~~^~~~~~~~~
main.cpp:66:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
66 | scanf("%d%d",&x,&y);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#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];
map<int,int> dp[505050];
int V[1<<20];
ll A[1<<19];
ll ret[1<<19];
const ll mo=998244353;
vector<int> mul[1<<20];
void dfs(int cur,int pre) {
vector<pair<int,int>> cand;
FORR(e,E[cur]) if(e!=pre) {
dfs(e,cur);
cand.push_back({dp[e].size(),e});
}
int i;
sort(ALL(cand));
reverse(ALL(cand));
FORR2(a,e,cand) {
FORR2(a,b,dp[e]) {
if(dp[cur][a]<b) {
(ret[cur]*=mul[a][b-dp[cur][a]-1])%=mo;
dp[cur][a]=b;
}
}
dp[e].clear();
}
}
void solve() {
int i,j,k,l,r,x,y; string s;
FOR(i,1000001) V[i]=i;
for(i=2;i<1000001;i++) if(V[i]==i) {
mul[i].push_back(i);
while(mul[i].back()*i<1000001) mul[i].push_back(mul[i].back()*i);
if(i<=1001) for(j=i*i;j<1000001;j+=i) V[j]=i;
}
scanf("%d",&N);
FOR(i,N) {
scanf("%d",&x);
ret[i]=x;
while(x>1) {
dp[i][V[x]]++;
x/=V[x];
}
}
FOR(i,N-1) {
scanf("%d%d",&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]<<"\n";
}
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