#include <bits/stdc++.h>
using namespace std;
int inf = 1e9;
const int N = 1e5 + 10;
bool prim[N];
int a[N], pos[N];
vector<int> v;
vector<pair<int, int> > ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(prim, 1, sizeof prim);
  for (int i = 2; i * i < N; i++) {
    if (prim[i])
      for (int j = i * i; j < N; j += i) prim[j] = 0;
  }
  for (int i = 2; i < N; i++)
    if (prim[i]) v.push_back(i);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    int p = pos[i];
    if (p == i) continue;
    while (i != p) {
      p = pos[i];
      int x = abs(p - i + 1);
      auto lp = upper_bound(v.begin(), v.end(), x);
      lp--;
      int y = *lp - 1;
      ans.push_back({pos[i] - y, pos[i]});
      swap(pos[i], pos[a[pos[i] - y]]);
      swap(a[pos[i]], a[pos[i] + y]);
      p = pos[i];
    }
  }
  cout << ans.size() << "\n";
  for (auto P : ans) cout << P.first << " " << P.second << "\n";
}
