結果

問題 No.2519 Coins in Array
ユーザー umezoumezo
提出日時 2023-10-27 23:40:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 1,982 bytes
コンパイル時間 2,877 ms
コンパイル使用メモリ 213,432 KB
実行使用メモリ 6,356 KB
最終ジャッジ日時 2023-10-27 23:40:25
合計ジャッジ時間 9,430 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,772 KB
testcase_01 AC 3 ms
4,772 KB
testcase_02 AC 3 ms
4,772 KB
testcase_03 AC 3 ms
4,772 KB
testcase_04 AC 3 ms
4,772 KB
testcase_05 AC 3 ms
4,772 KB
testcase_06 AC 3 ms
4,772 KB
testcase_07 AC 3 ms
4,772 KB
testcase_08 AC 3 ms
4,772 KB
testcase_09 AC 4 ms
4,772 KB
testcase_10 AC 3 ms
4,772 KB
testcase_11 AC 3 ms
4,772 KB
testcase_12 AC 4 ms
4,772 KB
testcase_13 AC 3 ms
4,772 KB
testcase_14 AC 3 ms
4,772 KB
testcase_15 AC 3 ms
4,772 KB
testcase_16 AC 3 ms
4,772 KB
testcase_17 AC 3 ms
4,772 KB
testcase_18 AC 3 ms
4,772 KB
testcase_19 AC 3 ms
4,772 KB
testcase_20 AC 3 ms
4,772 KB
testcase_21 AC 3 ms
4,772 KB
testcase_22 AC 3 ms
4,772 KB
testcase_23 AC 287 ms
6,356 KB
testcase_24 AC 285 ms
6,356 KB
testcase_25 AC 3 ms
4,772 KB
testcase_26 AC 3 ms
4,772 KB
testcase_27 AC 313 ms
6,356 KB
testcase_28 AC 286 ms
6,356 KB
testcase_29 AC 285 ms
6,356 KB
testcase_30 AC 256 ms
6,092 KB
testcase_31 AC 47 ms
5,036 KB
testcase_32 AC 138 ms
5,564 KB
testcase_33 AC 197 ms
5,828 KB
testcase_34 AC 95 ms
5,300 KB
testcase_35 AC 182 ms
5,828 KB
testcase_36 AC 77 ms
5,300 KB
testcase_37 AC 36 ms
5,036 KB
testcase_38 AC 152 ms
5,564 KB
testcase_39 AC 93 ms
5,300 KB
testcase_40 AC 277 ms
6,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

map<ll,ll> prime_factor(ll x){
  map<ll,ll> res;
  
  for(ll i=2;i*i<=x;i++){
    while(x%i==0){
      res[i]++;
      x/=i;
    }
  }
  if(x!=1) res[x]++;
  
  return res;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  vector<ll> B(200200,-1);
  int l=-1,r=-1;
  rep(i,n){
    map<ll,ll> m=prime_factor(A[i]);
    for(auto [a,b]:m){
      if(B[a]!=-1){
        l=B[a],r=i;
        break;
      }
      B[a]=i;
    }
    if(l!=-1) break;
  }
  if(l!=-1){
    cout<<0<<endl;
    cout<<l+1<<" "<<r+1<<endl;
    rep(i,n-2) cout<<1<<" "<<n-1-i<<endl;
    return 0;
  }
  
  if(n>=4){
    cout<<0<<endl;
    cout<<1<<" "<<2<<endl;
    cout<<1<<" "<<2<<endl;
    cout<<n-3<<" "<<n-2<<endl;
    rep(i,n-4) cout<<1<<" "<<n-3-i<<endl;
  }
  else if(n==2){
    cout<<(A[0]-1)*(A[1]-1)<<endl;
    cout<<1<<" "<<2<<endl;
  }
  else if(n==3){
    ll mi=1e18+7;
    int num=-1;
    
    ll tmp=(A[0]-1)*(A[1]-1);
    ll c=gcd(tmp,A[2]);
    if(c>1){
      mi=0;
      num=0;
    }
    else{
      if(mi>(tmp-1)*(A[2]-1)){
        mi=(tmp-1)*(A[2]-1);
        num=0;
      }
    }
    
    tmp=(A[0]-1)*(A[2]-1);
    c=gcd(tmp,A[1]);
    if(c>1){
      mi=0;
      num=1;
    }
    else{
      if(mi>(tmp-1)*(A[1]-1)){
        mi=(tmp-1)*(A[1]-1);
        num=1;
      }
    }
    
    tmp=(A[1]-1)*(A[2]-1);
    c=gcd(tmp,A[0]);
    if(c>1){
      mi=0;
      num=2;
    }
    else{
      if(mi>(tmp-1)*(A[0]-1)){
        mi=(tmp-1)*(A[0]-1);
        num=2;
      }
    }
    
    cout<<mi<<endl;
    if(num==0){
      cout<<1<<" "<<2<<endl;
      cout<<1<<" "<<2<<endl;
    }
    else if(num==1){
      cout<<1<<" "<<3<<endl;
      cout<<1<<" "<<2<<endl;
    }
    else{
      cout<<2<<" "<<3<<endl;
      cout<<1<<" "<<2<<endl;
    }
  }
    
  return 0;
}
0