結果
| 問題 |
No.2519 Coins in Array
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2023-10-27 23:40:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 308 ms / 2,000 ms |
| コード長 | 1,982 bytes |
| コンパイル時間 | 2,201 ms |
| コンパイル使用メモリ | 204,872 KB |
| 最終ジャッジ日時 | 2025-02-17 16:11:16 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 |
ソースコード
#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;
}
umezo