#include <bits/stdc++.h>
using namespace std;
int n, cnt;
int is[101010];
int a[101010], st[101010];
pair<int, int> ans[501010];
void init() {
  memset(is, 0, sizeof is);
  cnt = 0;
  for (int i = 2; i < 101010; i++) {
    if (i == 1) break;
    if (!is[i]) {
      for (int j = i + i; j < 101010; j += i) {
        is[j] = 1;
      }
    }
  }
}
int main() {
  init();
  int n, tt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    st[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    while (st[i] != i) {
      for (int j = i;; j++) {
        if (is[st[i] - j + 1] == 0) {
          int kk = a[j];
          swap(a[st[i]], a[j]);
          ans[tt].first = st[i];
          ans[tt].second = j;
          tt++;
          st[kk] = st[i];
          st[i] = j;
          break;
        }
      }
    }
  }
  cout << tt << endl;
  for (int i = 0; i < tt; i++) {
    printf("%d %d\n", ans[i].second, ans[i].first);
  }
  return 0;
}
