#include <bits/stdc++.h>
using namespace std;
bool prime[100005];
int primes[100005], cnt;
int pos[100005];
int num[100005];
int ans[100005 * 5][2];
void swap(int x, int y) {
  pos[num[x]] = pos[num[x]] ^ pos[num[y]];
  pos[num[y]] = pos[num[x]] ^ pos[num[y]];
  pos[num[x]] = pos[num[x]] ^ pos[num[y]];
  num[x] = num[x] ^ num[y];
  num[y] = num[x] ^ num[y];
  num[x] = num[x] ^ num[y];
}
void init() {
  memset(prime, true, sizeof prime);
  int i, j;
  for (i = 2; i <= 100005 - 5; i++) {
    for (j = 2; i * j <= 100005 - 5; j++) {
      prime[i * j] = false;
    }
  }
  for (i = 2; i <= 100005 - 5; i++) {
    if (prime[i]) primes[cnt++] = i - 1;
  }
}
int bs(int x) {
  int l = 0, r = cnt - 1, m;
  while (l < r) {
    int m = (l + r) >> 1;
    if (primes[m] <= x && x < primes[m + 1])
      return primes[m];
    else if (x < primes[m])
      r = m;
    else
      l = m + 1;
  }
}
int n;
int main() {
  init();
  scanf("%d", &n);
  int i;
  for (i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    pos[num[i]] = i;
  }
  int cntans = 0;
  for (i = 1; i <= n; i++) {
    while (1) {
      int dis = pos[i] - i;
      if (!dis) break;
      int maxm = bs(dis);
      ans[cntans][0] = pos[i] - maxm;
      ans[cntans++][1] = pos[i];
      swap(pos[i], pos[i] - maxm);
    }
  }
  printf("%d\n", cntans);
  for (i = 0; i < cntans; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  return 0;
}
