#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int ans[12 * MAXN];
int a[MAXN], b[MAXN], prime[MAXN], k = 0;
void ini() {
  memset(prime, 0, sizeof(prime));
  for (int i = 2; i < MAXN; i++)
    if (!prime[i]) {
      for (int j = i + i; j < MAXN; j += i) prime[j] = 1;
    }
}
void solve(int i, int j) {
  if (j > i) {
    while (j > i) {
      if (!prime[j - i + 1]) {
        b[a[i]] = j;
        swap(a[i], a[j]);
        ans[k++] = i;
        ans[k++] = j;
        break;
      }
      if (!prime[j - i + 1 - 1]) {
        b[a[j - 1]] = j;
        swap(a[j], a[j - 1]);
        ans[k++] = j - 1;
        ans[k++] = j;
        j -= 1;
        b[a[i]] = j;
        swap(a[i], a[j]);
        ans[k++] = i;
        ans[k++] = j;
        break;
      } else if (!prime[j - i + 1 - 2]) {
        b[a[j - 2]] = j;
        swap(a[j], a[j - 2]);
        ans[k++] = j - 2;
        ans[k++] = j;
        j -= 2;
        b[a[i]] = j;
        swap(a[i], a[j]);
        ans[k++] = i;
        ans[k++] = j;
        break;
      }
      b[a[j - 4]] = j;
      swap(a[j], a[j - 4]);
      ans[k++] = j - 4;
      ans[k++] = j;
      j -= 4;
    }
  } else if (j < i) {
    while (j < i) {
      if (!prime[i - j + 1]) {
        b[a[i]] = j;
        swap(a[i], a[j]);
        ans[k++] = j;
        ans[k++] = i;
        break;
      }
      if (!prime[i - j + 1 - 1]) {
        b[a[j + 1]] = j;
        swap(a[j], a[j + 1]);
        ans[k++] = j;
        ans[k++] = j + 1;
        j += 1;
        b[a[i]] = j;
        swap(a[i], a[j]);
        ans[k++] = j;
        ans[k++] = i;
        break;
      } else if (!prime[i - j + 1 - 2]) {
        b[a[j + 2]] = j;
        swap(a[j], a[j + 2]);
        ans[k++] = j;
        ans[k++] = j + 2;
        j += 2;
        b[a[i]] = j;
        swap(a[i], a[j]);
        ans[k++] = j;
        ans[k++] = i;
        break;
      }
      b[a[j + 4]] = j;
      swap(a[j + 4], a[j]);
      ans[k++] = j;
      ans[k++] = j + 4;
      j += 4;
    }
  }
}
int main() {
  ini();
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    int j = b[i];
    if (i != j) solve(i, j);
  }
  printf("%d\n", k / 2);
  for (int i = 0; i < k; i += 2) printf("%d %d\n", ans[i], ans[i + 1]);
}
