#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
bool notprime[N + 1];
void sieve() {
  notprime[0] = 1;
  notprime[1] = 1;
  for (long long i = 2; i * i <= N; i++) {
    if (!notprime[i]) {
      for (long long j = i * i; j <= N; j += i) {
        notprime[j] = 1;
      }
    }
  }
}
long long a[N], pos[N];
signed main() {
  sieve();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  for (long long i = 1; i < n + 1; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  std::vector<pair<long long, long long> > v;
  for (long long i = 1; i <= n; i++) {
    for (long long j = pos[i]; j > i;) {
      long long first = i;
      while (notprime[j - first + 1]) {
        first++;
      }
      pos[a[first]] = j, pos[a[j]] = first;
      v.push_back({first, j});
      swap(a[first], a[j]);
      j = first;
    }
  }
  cout << (long long)v.size() << '\n';
  for (auto i : v) {
    cout << i.first << ' ' << i.second << '\n';
  }
}
