結果

問題 No.2519 Coins in Array
ユーザー cho435cho435
提出日時 2023-10-28 14:03:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 3,605 ms
コンパイル使用メモリ 251,432 KB
最終ジャッジ日時 2025-02-17 16:39:53
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#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++)

ll f(ll a,ll b){
	if(gcd(a,b)==1) return (a-1)*(b-1);
	return 0;
}

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n) cin>>a.at(i);
	if(n>3){
		cout<<0<<endl;
		cout<<"1 2\n";
		cout<<"1 2\n";
		cout<<n-2<<" "<<n-3<<"\n";
		rep(i,n-4){
			cout<<"1 "<<n-3-i<<"\n";
		}
	}else{
		if(n==2){
			cout<<f(a.at(0),a.at(1))<<"\n";
			cout<<"1 2\n";
		}else{
			vector<int> v={a.at(0),a.at(1),a.at(2)};
			ll mn=1e18;
			int j=-1;
			rep(i,3){
				ll tmp=f(f(v.at(0),v.at(1)),v.at(2));
				if(mn>tmp){
					mn=tmp;
					j=i;
				}
				v.push_back(v.front());
				v.erase(v.begin());
			}
			cout<<mn<<"\n";
			cout<<j+1<<" "<<(j+1)%3+1<<"\n";
			cout<<"1 2\n";
		}
	}
}
0