#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 2e5 + 100;
long n, a[MAXN], pos[MAXN], pp[MAXN];
vector<long> p;
set<long> prime;
vector<pair<long, long>> res;
void check(long aa, long bb) {
  swap(a[aa], a[bb]);
  swap(pos[a[aa]], pos[a[bb]]);
  res.push_back({aa, bb});
}
int main() {
  int t = 1;
  while (t--) {
    cin >> n;
    for (int i = 1; i < n + 1; i++) {
      cin >> a[i];
      pos[a[i]] = i;
    }
    pp[1] = 1;
    for (int i = 2; i < MAXN; i++)
      if (pp[i] == 0)
        for (int j = 2 * i; j < MAXN; j += i) pp[j] = 1;
    for (int i = 1; i < MAXN; i++)
      if (pp[i] == 0) {
        p.push_back(i);
        prime.insert(i);
      }
    for (int i = 1; i < n + 1; i++) {
      while (1) {
        if (a[i] == i) break;
        long ok = pos[i] - i + 1;
        auto it = prime.upper_bound(ok);
        --it;
        long val = (*it);
        check(pos[i] - val + 1, pos[i]);
      }
    }
    cout << res.size() << endl;
    for (int i = 0; i < res.size(); i++)
      cout << res[i].first << " " << res[i].second << endl;
  }
  return 0;
}
