結果
| 問題 |
No.2756 GCD Teleporter
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-11 17:16:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 833 bytes |
| コンパイル時間 | 4,340 ms |
| コンパイル使用メモリ | 263,052 KB |
| 最終ジャッジ日時 | 2025-02-21 13:40:54 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 WA * 9 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;
template<class T>
void chmin(T &a,T b){
if(a>b) a=b;
}
int main(){
int n;
cin>>n;
vector<int> a(n);
rep(i,n) cin>>a.at(i);
map<ll,vector<int>> mp;
rep(i,n){
int tmp=a.at(i);
for(ll j=2;j*j<=tmp;j++){
if(tmp%j==0){
mp[j].push_back(i);
while(tmp%j==0) tmp/=j;
}
}
if(tmp>1) mp[tmp].push_back(i);
}
atcoder::dsu uf(n);
for(auto&[x,v]:mp){
for(auto&y:v){
uf.merge(v.at(0),y);
}
}
vector<ll> sc(n,1e18);
for(auto&[x,v]:mp){
for(auto&y:v){
chmin(sc.at(uf.leader(y)),x);
}
}
ll mn=1e18;
set<int> st;
rep(i,n){
st.insert(uf.leader(i));
chmin(mn,sc.at(uf.leader(i)));
}
cout<<(ll)mn*(st.size()-1)<<endl;
}