#include <bits/stdc++.h>
using namespace std;
long long int arr[200000], inv[200000];
int main() {
  long long int n, i, j, p, l;
  cin >> n;
  vector<long long int> sieve(100001, 1);
  vector<pair<long long int, long long int> > ans;
  for (i = 2; i <= 100000; ++i) {
    for (j = 2; i * j <= 100000; ++j) {
      sieve[i * j] = 0;
    }
  }
  for (i = 1; i <= n; ++i) {
    cin >> arr[i];
    inv[arr[i]] = i;
  }
  for (i = 1; i <= n; ++i) {
    while (arr[i] != i) {
      p = inv[i];
      l = i;
      while (sieve[abs(p - l + 1)] == 0) {
        l++;
      }
      ans.push_back(make_pair(l, p));
      swap(inv[arr[l]], inv[arr[p]]);
      swap(arr[l], arr[p]);
    }
  }
  cout << ans.size() << endl;
  for (i = 0; i < ans.size(); ++i) {
    printf("%lld %lld \n", ans[i].first, ans[i].second);
  }
}
