#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 300;
bool ispr[MAX + 305];
vector<int> primes;
void sieve() {
  memset(ispr, 1, sizeof ispr);
  for (int i = 4; i <= MAX; i += 2) ispr[i] = 0;
  ispr[0] = ispr[1] = 0;
  primes.push_back(2);
  for (int i = 3; i <= MAX; i++) {
    if (ispr[i]) {
      primes.push_back(i);
      for (long long j = (long long)i * i; j <= MAX; j += i) ispr[j] = 0;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  sieve();
  int n;
  cin >> n;
  vector<int> all(n), pos(n);
  for (int i = 0; i < n; i++) {
    cin >> all[i];
  }
  vector<pair<int, int> > ans;
  for (int i = 0; i < n;) {
    int num = all[i];
    int need = num - 1;
    if (i != need) {
      int j = i;
      int diff = abs(j - need) + 1;
      while (diff > 1) {
        auto it = lower_bound(primes.begin(), primes.end(), diff);
        if (*it > diff) it--;
        ans.push_back({j + 1, j + *it});
        swap(all[j], all[j + *it - 1]);
        j += (*it) - 1;
        diff = abs(j - need) + 1;
      }
    } else
      i++;
  }
  cout << ans.size() << '\n';
  for (pair<int, int> x : ans) cout << x.first << " " << x.second << '\n';
  return 0;
}
