#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int val[maxn];
int sito[maxn];
int main() {
  ios::sync_with_stdio(false);
  for (int i = 0; i < maxn; i++) {
    sito[i] = true;
  }
  vector<int> v;
  sito[0] = sito[1] = false;
  for (int i = 2; i < maxn; i++) {
    if (sito[i]) {
      v.push_back(i);
      if (i < 1000) {
        for (int j = i * i; j < maxn; j += i) {
          sito[j] = false;
        }
      }
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> val[i];
    val[i]--;
  }
  vector<pair<int, int> > ss;
  for (int i = 0; i < n;) {
    int pos = i;
    if (pos == val[pos]) {
      i++;
      continue;
    }
    while (pos != val[pos]) {
      int l = 0, r = v.size() - 1;
      int best = 0;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (pos + v[mid] - 1 <= val[pos]) {
          l = mid + 1;
          best = max(best, v[mid] - 1);
        } else {
          r = mid - 1;
        }
      }
      ss.push_back(make_pair(pos + 1, pos + best + 1));
      swap(val[pos], val[pos + best]);
      pos += best;
    }
  }
  cout << ss.size() << endl;
  for (int i = 0; i < ss.size(); i++) {
    cout << ss[i].first << ' ' << ss[i].second << '\n';
  }
}
