#include <bits/stdc++.h>
using namespace std;
struct el {
  int i, value;
};
bool isEASy(int k) {
  int sq = sqrt(double(k));
  for (int i = 2; i <= sq; ++i)
    if (k % i == 0) return false;
  return true;
}
vector<el> res;
int find_easy_near(int a, int b) {
  int otv;
  if (a > b)
    otv = a - b;
  else
    otv = b - a;
  while (!isEASy(otv + 1)) {
    --otv;
  }
  return otv;
}
int add_otv(int a, int b) {
  el t;
  if (a < b) {
    t.i = a;
    t.value = b;
  } else {
    t.i = b;
    t.value = a;
  }
  res.push_back(t);
}
int main() {
  int n;
  scanf("%d", &n);
  int a[100005];
  int pos[100005];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    --a[i];
    pos[a[i]] = i;
  }
  for (int i = 0; i < n; ++i) {
    while (a[i] != i) {
      int otv = find_easy_near(i, pos[i]);
      int new_i;
      if (pos[i] > i) {
        new_i = pos[i] - otv;
      } else {
        new_i = pos[i] + otv;
      }
      add_otv(pos[i], new_i);
      int t = a[new_i];
      a[pos[i]] = t;
      pos[t] = pos[i];
      a[new_i] = i;
      pos[i] = new_i;
    }
  }
  printf("%d\n", res.size());
  for (int i = 0; i < res.size(); ++i) {
    printf("%d %d\n", res[i].i + 1, res[i].value + 1);
  }
  return 0;
}
