#include <bits/stdc++.h>
using namespace std;
int a[100002];
int x[100002];
bool p[100002];
int main() {
  vector<int> v;
  for (int(i) = (2); (i) <= (100001); ++(i)) {
    bool f = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        f = false;
        break;
      }
    }
    if (f) p[i] = true;
  }
  int n;
  scanf("%d", &n);
  for (int(i) = (1); (i) <= (n); ++(i)) {
    scanf("%d", &x[i]);
    a[x[i]] = i;
  }
  int cn = 0;
  vector<pair<int, int> > ret;
  for (int i = n; i > 0; i--) {
    while (a[i] != i) {
      int j = i;
      for (; !p[j - a[i] + 1]; j--)
        ;
      ret.push_back(pair<int, int>(a[i], j));
      swap(x[a[i]], x[j]);
      a[x[a[i]]] = a[i];
      a[x[j]] = j;
      cn++;
    }
  }
  printf("%d\n", cn);
  for (int(i) = (0); (i) < (ret.size()); ++(i))
    printf("%d %d\n", ret[i].first, ret[i].second);
  return 0;
}
