#include <bits/stdc++.h>
using namespace std;
int vis[100005 + 5], prime[100005 + 5], a[100005], pos[100005], c, cnt;
struct node {
  int x, y;
} ans[100005 * 5];
void get_prime() {
  memset(vis, 0, sizeof(vis));
  cnt = 0;
  for (int i = 2; i <= 100005; i++) {
    if (!vis[i]) {
      prime[cnt++] = i;
      for (int j = i + i; j <= 100005; j += i) vis[j] = 1;
    }
  }
}
void solve(int x, int y) {
  if (x == y) return;
  int tmp = abs(y - x), L = 0, R = cnt - 1, M;
  while (L < R) {
    M = (L + R) >> 1;
    if (prime[M] - 1 == tmp) {
      ans[c].x = x;
      ans[c].y = y;
      c++;
      a[y] = a[x];
      pos[a[x]] = y;
      return;
    }
    if (prime[M] > tmp) {
      R = M;
    } else {
      L = M + 1;
    }
  }
  tmp = prime[L - 1];
  pos[a[y - tmp + 1]] = y;
  a[y] = a[y - tmp + 1];
  ans[c].x = y - tmp + 1;
  ans[c].y = y;
  c++;
  solve(x, y - tmp + 1);
}
int main() {
  int n, i;
  get_prime();
  while (~scanf("%d", &n)) {
    c = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      pos[a[i]] = i;
    }
    for (i = 1; i <= n; i++) {
      solve(i, pos[i]);
    }
    printf("%d\n", c);
    for (i = 0; i < c; i++) printf("%d %d\n", ans[i].x, ans[i].y);
  }
  return 0;
}
