#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 100, N = 2e5 + 5;
const long long INF = 1e18 + 100, MOD = 1e9 + 7;
long long powmod(long long a, long long b, long long m = MOD) {
  long long r = 1;
  while (b > 0) {
    if (b & 1) r = r * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return r;
}
long long power(long long a, long long b) {
  long long r = 1;
  while (b > 0) {
    if (b & 1) r = r * a;
    a = a * a;
    b >>= 1;
  }
  return r;
}
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long inv(long long a, long long m = MOD) { return powmod(a, m - 2, m); }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int a[N], n, pos[N];
vector<int> pr;
vector<pair<int, int> > ans;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0),
      cout << setprecision(10) << fixed;
  ;
  cin >> n;
  for (int i = 2; i <= N; ++i) {
    bool ok = 1;
    for (long long j = 2; j * j <= i; ++j) {
      if (i % j == 0) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      pr.push_back(i);
    }
  }
  for (int i = 1; i <= n; ++i) cin >> a[i], pos[a[i]] = i;
  for (int i = 1; i <= n; ++i) {
    int curr = pos[i];
    while (curr != i) {
      int diff = curr - i + 1;
      int p = upper_bound(pr.begin(), pr.end(), diff) - pr.begin();
      p--;
      swap(a[curr], a[curr - pr[p] + 1]);
      pos[a[curr]] = curr;
      pos[a[curr - pr[p] + 1]] = curr - pr[p] + 1;
      ans.push_back({curr - pr[p] + 1, curr});
      curr = curr - pr[p] + 1;
    }
  }
  cout << (int)ans.size() << "\n";
  for (auto x : ans) cout << x.first << " " << x.second << "\n";
}
