#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int a[N + 10], b[N + 10];
bool p[N];
void init() {
  memset(p, 0, sizeof(p));
  p[0] = p[1] = 1;
  for (int i = 2; i < N; i++) {
    if (p[i]) continue;
    for (int j = i << 1; j < N; j += i) p[j] = 1;
  }
}
int ans[N * 5][2];
int main() {
  init();
  int n, m;
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", a + i);
      b[a[i]] = i;
    }
    m = 0;
    for (int i = 1; i <= n; i++) {
      while (b[i] != i) {
        for (int j = i; j < b[i]; j++) {
          if (!p[b[i] - j + 1]) {
            ans[m][0] = j;
            ans[m][1] = b[i];
            m++;
            swap(a[b[i]], a[j]);
            swap(b[a[b[i]]], b[a[j]]);
            break;
          }
        }
      }
    }
    printf("%d\n", m);
    for (int i = 0; i < m; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  }
  return 0;
}
