結果
| 問題 |
No.2756 GCD Teleporter
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2024-05-10 22:09:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 370 ms / 2,000 ms |
| コード長 | 1,021 bytes |
| コンパイル時間 | 4,154 ms |
| コンパイル使用メモリ | 256,592 KB |
| 最終ジャッジ日時 | 2025-02-21 12:50:53 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 |
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001
int main(){
int n;
cin>>n;
vector<vector<int>> ps(n);
vector<int> p;
rep(i,n){
int a;
cin>>a;
for(int j=2;j*j<=a;j++){
if(a%j==0){
ps[i].push_back(j);
p.push_back(j);
while(a%j==0){
a/=j;
}
}
}
if(a>1){
ps[i].push_back(a);
p.push_back(a);
}
}
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
if(p.size()==0){
cout<<n*2<<endl;
return 0;
}
int m = p.size();
dsu D(n+m);
rep(i,n){
for(int j:ps[i]){
int k = lower_bound(p.begin(),p.end(),j)-p.begin();
D.merge(i,n+k);
}
}
long long G = D.groups().size();
long long ans = (G-1) * p[0];
ans = min(ans,G * 2);
cout<<ans<<endl;
return 0;
}
沙耶花