#include <bits/stdc++.h>
using namespace std;
int t, n, m;
int table[100010], a[100010], pos[100010];
vector<int> ans1;
vector<int> ans2;
void init() {
  table[0] = table[1] = 1;
  for (int i = 2; i * i < 100010; i++) {
    for (int j = i * i; j < 100010; j += i) {
      table[j] = 1;
    }
  }
}
int main() {
  init();
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      pos[a[i]] = i;
    }
    ans1.clear();
    ans2.clear();
    for (int i = 1; i <= n; i++) {
      while (1) {
        if (pos[i] == i) break;
        for (int j = i; j < pos[i]; j++) {
          if (!table[pos[i] - j + 1]) {
            int x = pos[i], y = j;
            pos[i] = y;
            pos[a[j]] = x;
            ans1.push_back(y);
            ans2.push_back(x);
            swap(a[x], a[y]);
          }
        }
      }
    }
    cout << ans1.size() << endl;
    for (int i = 0; i < ans1.size(); i++) {
      printf("%d %d\n", ans1[i], ans2[i]);
    }
  }
  return 0;
}
