#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ans;
const int N = 100005;
int seive[N], best[N], pos[N], a[N];
void change(int x, int y) {
  ans.push_back(make_pair(x, y));
  swap(a[x], a[y]);
  swap(pos[a[x]], pos[a[y]]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  for (int i = 2; i < N; i++) {
    if (seive[i] == 0) {
      best[i] = i;
      for (int j = 2 * i; j < N; j += i) {
        seive[j] = 1;
      }
    } else {
      best[i] = best[i - 1];
    }
  }
  int n, k, i;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i;
  for (i = 1; i <= n; i++) {
    if (pos[i] != i) {
      while (pos[i] != i) {
        k = best[pos[i] - i + 1];
        assert(k >= 2);
        change(pos[i] - k + 1, pos[i]);
      }
    }
  }
  cout << ans.size() << "\n";
  for (auto x : ans) cout << x.first << " " << x.second << "\n";
}
