結果
| 問題 | 
                            No.2756 GCD Teleporter
                             | 
                    
| コンテスト | |
| ユーザー | 
                             沙耶花
                         | 
                    
| 提出日時 | 2024-05-10 22:07:35 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 965 bytes | 
| コンパイル時間 | 4,279 ms | 
| コンパイル使用メモリ | 257,436 KB | 
| 最終ジャッジ日時 | 2025-02-21 12:50:21 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 35 RE * 1 | 
ソースコード
#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());
  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;
}
            
            
            
        
            
沙耶花