#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; ll f(const ll i, const ll j) { return gcd(i, j) == 1 ? (i - 1) * (j - 1) : 0; } int main() { constexpr int A = 200000; int n; cin >> n; vector a(n); REP(i, n) cin >> a[i]; vector> ans; const auto finish = [&]() -> void { const int m = n - ans.size(); for (int i = m - 1; i >= 1; --i) { ans.emplace_back(i - 1, i); } cout << 0 << '\n'; for (const auto& [i, j] : ans) cout << i + 1 << ' ' << j + 1 << '\n'; exit(0); }; REP(i, n) { if (a[i] == 0 || a[i] == 1) { ans.emplace_back(i, (i + 1) % n); finish(); } } array indices{}; fill(indices.begin(), indices.end(), -1); REP(i, n) { if (indices[a[i]] != -1) { ans.emplace_back(indices[a[i]], i); finish(); } indices[a[i]] = i; } for (int d = 2; d <= A; ++d) { int memo = -1; for (int i = d; i <= A; i += d) { if (memo == -1) { memo = indices[i]; } else if (memo != -1 && indices[i] != -1) { ans.emplace_back(memo, indices[i]); finish(); } } } vector odd; REP(i, n) { if (a[i] % 2 == 1) odd.emplace_back(i); } if (odd.size() >= 4) { odd.resize(4); ans.emplace_back(odd.front(), odd[1]); ans.emplace_back(odd.end()[-2], odd.back()); ans.emplace_back(n - 4, n - 3); finish(); } if (n == 2) { cout << f(a.front(), a.back()) << '\n' << 1 << ' ' << 2 << '\n'; return 0; } if (n == 4) { assert(odd.size() == 3); ans.emplace_back(odd.front(), odd[1]); a.erase(next(a.begin(), odd[1])); a.erase(next(a.begin(), odd.front())); a.emplace_back(f(a[odd.front()], a[odd[1]])); REP(i, a.size()) FOR(j, i + 1, a.size()) { if (a[i] % 2 == 0 && a[j] % 2 == 0) { ans.emplace_back(i, j); finish(); } } } assert(n == 3); ll v = LINF; REP(i, n) FOR(j, i + 1, n) { const int k = i ^ j ^ 0 ^ 1 ^ 2; if (chmin(v, f(f(a[i], a[j]), a[k]))) ans = {{i, j}, {0, 1}}; } cout << v << '\n'; for (const auto& [i, j] : ans) cout << i + 1 << ' ' << j + 1 << '\n'; return 0; }