import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } br.close(); if (n >= 4) { PrintWriter pw = new PrintWriter(System.out); pw.println(0); pw.println("1 2"); pw.println("1 2"); for (int i = n - 2; i >= 2; i--) { pw.println("1 " + i); } pw.flush(); } else { Set set = new HashSet<>(); Map map0 = bunkai(a[0]); for (Integer k : map0.keySet()) { set.add(k); } long m = a[0]; for (int i = 1; i < n; i++) { Map map = bunkai(a[i]); for (Integer k : map.keySet()) { if (!set.add(k)) { m = 0; break; } } if (m != 0) { m = (m - 1) * (a[i] - 1); } } System.out.println(m); for (int i = 0; i < n - 1; i++) { System.out.println("1 2"); } throw new RuntimeException(); } } static Map bunkai(int n) { Map soinsu = new HashMap<>(); int end = (int) Math.sqrt(n); int d = 2; while (n > 1) { if (n % d == 0) { n /= d; soinsu.put(d, soinsu.getOrDefault(d, 0) + 1); end = (int) Math.sqrt(n); } else { if (d > end) { d = n - 1; } d++; } } return soinsu; } }