#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
bool isPrime[N];
vector<int> primes;
vector<int> adj[N];
void init() {
  memset(isPrime, true, sizeof(isPrime));
  for (int i = 2; i * i <= N; i++)
    if (isPrime[i]) {
      for (int j = i * i; j < N; j += i) isPrime[j] = false;
    }
  for (int i = (2); i < (N); i++)
    if (isPrime[i]) primes.push_back(i);
}
vector<int> a;
set<pair<int, int> > s;
inline void mySwap(int j, int i) {
  s.erase(make_pair(-a[i], i));
  s.insert(make_pair(-a[i], j));
  swap(a[i], a[j]);
}
int main() {
  init();
  adj[2].push_back(2);
  for (int i = 4; i < N; i += 2) {
    for (int j = 0; primes[j] < i; j++) {
      if (binary_search(primes.begin(), primes.end(), i - primes[j])) {
        adj[i].push_back(primes[j]);
        adj[i].push_back(i - primes[j]);
        break;
      }
    }
    assert((int)adj[i].size() == 2);
  }
  int n;
  cin >> n;
  a.resize(n);
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    s.insert(make_pair(-a[i], i));
  }
  vector<pair<int, int> > ans;
  for (int i = 0; i < (n); i++) {
    pair<int, int> cur = *s.begin();
    s.erase(s.begin());
    int pos = cur.second;
    int end = n - i - 1;
    int diff = (end - pos);
    if (diff == 0) continue;
    if (isPrime[diff + 1]) {
      ans.push_back(make_pair(pos, end));
      mySwap(pos, end);
      continue;
    } else {
      if (diff % 2 == 0) {
        diff += 2;
        assert((int)adj[diff].size() % 2 == 0);
        int len1 = adj[diff][0], len2 = adj[diff][1];
        assert(len1 + len2 == diff);
        ans.push_back(make_pair(pos, pos + len1 - 1));
        mySwap(pos, pos + len1 - 1);
        ans.push_back(make_pair(pos + len1 - 1, end));
        mySwap(pos + len1 - 1, end);
        continue;
      } else {
        ans.push_back(make_pair(pos, pos + 1));
        mySwap(pos, pos + 1);
        diff += 1;
        pos += 1;
        int len1 = adj[diff][0], len2 = adj[diff][1];
        assert(len1 + len2 == diff);
        ans.push_back(make_pair(pos, pos + len1 - 1));
        mySwap(pos, pos + len1 - 1);
        ans.push_back(make_pair(pos + len1 - 1, end));
        mySwap(pos + len1 - 1, end);
        continue;
      }
    }
  }
  cout << (int)ans.size() << endl;
  for (int i = 0; i < ((int)ans.size()); i++) {
    int l = min(ans[i].first, ans[i].second) + 1;
    int r = max(ans[i].first, ans[i].second) + 1;
    assert(isPrime[r - l + 1]);
    cout << l << " " << r << endl;
  }
  return 0;
}
