#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> v(n);
  map<int, int> m;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    m[v[i]] = i;
  }
  vector<bool> pr(n + 1);
  pr[0] = pr[1] = true;
  for (int i = 2; i <= n; ++i) {
    if (pr[i] == true) continue;
    for (int j = 2 * i; j <= n; j += i) {
      pr[j] = true;
    }
  }
  set<int> sp;
  for (int i = 0; i < pr.size(); ++i) {
    if (pr[i] == false) {
      sp.insert(i - 1);
    }
  }
  vector<int> s = v;
  sort(s.begin(), s.end());
  vector<pair<int, int> > ans;
  for (int i = 0; i < n; ++i) {
    if (s[i] == v[i]) continue;
    int cur = m[s[i]];
    while (cur > i) {
      auto it = sp.lower_bound(cur - i);
      int cp = 1;
      if (it != sp.end()) {
        cp = *it;
        if (cur - i != cp) cp = *(--it);
      }
      ans.push_back(make_pair(cur, cur - cp));
      swap(m[v[cur]], m[v[cur - cp]]);
      swap(v[cur], v[cur - cp]);
      cur -= cp;
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << min(ans[i].first, ans[i].second) + 1 << " "
         << max(ans[i].first, ans[i].second) + 1 << endl;
  }
  for (int i = 0; i < v.size(); ++i) {
    if (v[i] != s[i])
      while (1)
        ;
  }
}
