#include <bits/stdc++.h>
using namespace std;
struct sajal {
  long long i, j;
};
sajal l[600003];
long long b[100003], p[100003], a[100003];
int main() {
  long n, m;
  cin >> n;
  for (long i = 1; i <= n; i++) {
    cin >> a[i];
    p[a[i]] = i;
  }
  long h = 100000;
  long u = sqrt(h);
  for (long i = 2; i <= u; i++) {
    if (b[i] == 0) {
      for (long j = i + i; j <= h; j = j + i) b[j] = 1;
    }
  }
  b[1] = 1;
  u = 0;
  for (long i = 2; i <= h; i++) {
    if (b[i] == 0) {
      b[i] = i;
      u = i;
    } else
      b[i] = u;
  }
  long k = 0;
  for (long i = 1; i <= n; i++) {
    while (p[i] != i) {
      long h = p[i] - i + 1;
      if (h < 0) h = -h;
      long r = b[h];
      l[k].i = p[i];
      l[k].j = p[i] - r + 1;
      k++;
      long e = p[i] - r + 1;
      long w = p[i];
      long f = a[p[i] - r + 1];
      p[f] = p[i];
      p[i] = e;
      a[e] = i;
      a[w] = f;
    }
  }
  cout << k << endl;
  for (long i = 0; i < k; i++) {
    cout << l[i].j << " " << l[i].i << endl;
  }
}
