#include <bits/stdc++.h>
using namespace std;
template <class T>
vector<bool> sieve(T n) {
  vector<bool> prime;
  for (T i = 0; i <= n; i++) {
    prime.push_back(true);
  }
  prime[0] = false;
  prime[1] = false;
  long long m = sqrtl(n);
  for (T i = 2; i <= m; i++) {
    if (prime[i]) {
      for (T k = i * i; k <= n; k += i) {
        prime[k] = false;
      }
    }
  }
  return prime;
}
vector<bool> V;
int P[100000 + 5], Pos[100000 + 5], A[100000 + 5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(15);
  V = sieve(100000 + 5);
  for (int i = 2; i < 100000 + 4; i++) {
    if (V[i])
      P[i] = i;
    else
      P[i] = P[i - 1];
  }
  int n, s = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    Pos[x] = i;
    A[i] = x;
  }
  vector<int> X, Y;
  for (int i = 1; i <= n; i++) {
    int p = Pos[i];
    if (p == i) continue;
    while (1) {
      int x = P[p - i + 1];
      int y = A[p - x + 1];
      X.push_back(p - x + 1);
      Y.push_back(p);
      swap(A[p - x + 1], A[p]);
      Pos[y] = p;
      p = p - x + 1;
      Pos[i] = p;
      s++;
      if (p == i) break;
    }
  }
  cout << (int)X.size() << '\n';
  for (int i = 0; i < (int)X.size(); i++) {
    cout << X[i] << " " << Y[i] << '\n';
  }
  return 0;
}
