#include <bits/stdc++.h>
using namespace std;
int getint() {
  int s = 0, o = 1;
  char c;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') o = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) s *= 10, s += c - '0';
  return s * o;
}
const int maxn = 100010;
int a[maxn], c[maxn], b[maxn];
vector<int> p;
std::vector<pair<int, int> > r;
int n;
int main(int argc, char const *argv[]) {
  for (int i = 2; i < maxn; i++) {
    if (!a[i]) p.push_back(i);
    for (int j = i; j <= (maxn - 1) / i; j++) a[j * i] = 1;
  }
  b[0] = 0;
  for (int i = 2; i < maxn; i++) {
    b[i] = 10;
    int j = lower_bound(p.begin(), p.end(), i) - p.begin(), t = 0;
    for (int t = 0; t < 10; t++) {
      if (p[j] <= i && b[i - p[j]] + 1 < b[i])
        b[i] = b[i - p[j]] + 1, c[i] = p[j];
      if (j) j--;
    }
  }
  n = getint();
  for (int i = 1; i < 1 + n; i++) a[i] = getint(), b[a[i]] = i;
  for (int i = 1; i < 1 + n; i++) {
    while (b[i] > i) {
      int j = b[i] - i + 1, k = b[i] - c[j] + 1;
      r.push_back(make_pair(b[i], b[i] - c[j] + 1));
      a[b[i]] = a[k], b[a[k]] = b[i];
      a[k] = i, b[i] = k;
    }
  }
  printf("%d\n", r.size());
  for (int i = 0; i < r.size(); i++) printf("%d %d\n", r[i].second, r[i].first);
  return 0;
}
