#include #include // url #define rep(i,a,b) for(int i=a;i=a;i--) #define all(x) (x).begin(),(x).end() #define pb(x) push_back(x); templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b P; int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); // int x,y;cin >> x >> y; // rep(z,1,x*y+1){ // int a=0; // cout << z << " "; // while(a*x<=z){ // int b=z-a*x; // if(b%y==0){ // cout << a << " " << b/y << endl; // break; // } // a++; // } // if(a*x>z){ // cout << -1 << " " << -1 << endl; // } // } Init(); fill(idx,idx+eratosSize,-1); int N;cin >> N; vector

A(N); int a=-1,b=-1; int one=-1; rep(i,0,N){ cin >> A[i].first; A[i].second=i; if(A[i].first<=1)one=i; if(a!=-1)continue; int tmp=A[i].first; while(tmp>1){ int p=eratos[tmp]; if(idx[p]==-1){ idx[p]=i; } else if(idx[p]!=i){ a=idx[p]; b=i; break; } while(tmp%p==0){ tmp/=p; } } } if(a!=-1){ cout << 0 << endl; cout << a+1 << " " << b+1 << endl; rrep(i,1,N-1){ cout << 1 << " " << i+1 << endl; } } else if(one!=-1){ cout << 0 << endl; cout << one+1 << " " << 1 << endl; rrep(i,1,N-1){ cout << 1 << " " << i+1 << endl; } } else if(N==2){ ll M=(A[0].first-1)*(A[1].first-1); cout << M << endl; cout << 1 << " " << 2 << endl; } else if(idx[2]!=-1&&N>=3){ int x=-1,y=-1; rep(i,0,N){ if(A[i].first==2)continue; if(x==-1){ x=i; } else{ y=i; } } cout << 0 << endl; cout << x+1 << " " << y+1 << endl; int z=idx[2]; if(x=4){ cout << 0 << endl; cout << N-1 << " " << N << endl; cout << N-3 << " " << N-2 << endl; rrep(i,1,N-2){ cout << 1 << " " << i+1 << endl; } } else{ ll M=inf; int x=-1,y=-1; rep(a,0,3)rep(b,a+1,3){ ll tmp=(A[a].first-1)*(A[b].first-1); int c=3-a-b; ll g=gcd(tmp,A[c].first); if(g!=1){ if(chmin(M,0ll)){ x=a; y=b; } } else{ tmp=(tmp-1)*(A[c].first-1); if(chmin(M,tmp)){ x=a; y=b; } } } cout << M << endl; cout << x+1 << " " << y+1 << endl; cout << 1 << " " << 2 << endl; } }