import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class CompatibleTrees_lewin { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); CompatibleTrees solver = new CompatibleTrees(); solver.solve(1, in, out); out.close(); } static class CompatibleTrees { public int mod = 1000000007; public int n; public long[][][] dp; public int[] x; public boolean[][] conn; public long solve(int from, int to, int mode) { if ((from + 1) % n == to) return 1; if (dp[from][to][mode] != -1) { return dp[from][to][mode]; } int tt = (from + 1) % n; long ret = 0; while (tt != to) { if (conn[from][tt] && mode == 0) { ret = (ret + solve(from, tt, 0) * solve(tt, to, 0)) % mod; } if (conn[tt][to]) { ret = (ret + solve(from, tt, 1) * solve(tt, to, 0)) % mod; } tt = (tt + 1) % n; } return dp[from][to][mode] = ret; } public void solve(int testNumber, InputReader in, OutputWriter out) { n = in.nextInt(); if (n == 1) { out.println(1); return; } x = in.readIntArray(n); conn = new boolean[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { conn[i][j] = Utils.gcd(x[i], x[j]) > 1; } } dp = new long[n][n][2]; for (long[][] y : dp) for (long[] z : y) Arrays.fill(z, -1); long nways = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (conn[i][j]) { nways = (nways + solve(i, j, 0) * solve(j, i, 0) % mod) % mod; } } } nways = nways * Utils.inv(n - 1, mod) % mod; out.println(nways); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int[] readIntArray(int tokens) { int[] ret = new int[tokens]; for (int i = 0; i < tokens; i++) { ret[i] = nextInt(); } return ret; } public int read() { if (this.numChars == -1) { throw new InputMismatchException(); } else { if (this.curChar >= this.numChars) { this.curChar = 0; try { this.numChars = this.stream.read(this.buf); } catch (IOException var2) { throw new InputMismatchException(); } if (this.numChars <= 0) { return -1; } } return this.buf[this.curChar++]; } } public int nextInt() { int c; for (c = this.read(); isSpaceChar(c); c = this.read()) { ; } byte sgn = 1; if (c == 45) { sgn = -1; c = this.read(); } int res = 0; while (c >= 48 && c <= 57) { res *= 10; res += c - 48; c = this.read(); if (isSpaceChar(c)) { return res * sgn; } } throw new InputMismatchException(); } public static boolean isSpaceChar(int c) { return c == 32 || c == 10 || c == 13 || c == 9 || c == -1; } } static class Utils { public static long inv(long N, long M) { long x = 0, lastx = 1, y = 1, lasty = 0, q, t, a = N, b = M; while (b != 0) { q = a / b; t = a % b; a = b; b = t; t = x; x = lastx - q * x; lastx = t; t = y; y = lasty - q * y; lasty = t; } return (lastx + M) % M; } public static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void println(long i) { writer.println(i); } public void println(int i) { writer.println(i); } } }