#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 42;
int pos[N], erat[N], a[N];
set<int> primes;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (long long i = 2; i < N; i++)
    if (!erat[i]) {
      primes.insert(i);
      for (long long j = i * i; j < N; j += i) erat[j] = i;
    }
  int n = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  vector<pair<int, int> > ans;
  for (int i = 1; i <= n; i++) {
    while (pos[i] != i) {
      int left = pos[i] - i + 1;
      auto it = primes.upper_bound(left);
      it--;
      int l = pos[i] - *it + 1;
      int cp = pos[i];
      pos[a[l]] = cp;
      pos[a[cp]] = l;
      swap(a[l], a[cp]);
      ans.push_back(make_pair(l, cp));
    }
  }
  cout << ans.size() << endl;
  for (auto& x : ans) cout << x.first << ' ' << x.second << endl;
  return 0;
}
