#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long int arr[100010], pos[100010];
vector<pair<long long, long long> > out;
set<long long int> p;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    pos[arr[i] - 1] = i;
  }
  p.insert(2);
  for (long long int i = 3; i < 100000; i += 2) {
    for (auto x : p) {
      if (x * x > i) {
        p.insert(i);
        break;
      }
      if (i % x == 0) break;
    }
  }
  for (long long int i = 0; i < n; i++) {
    while (pos[i] != i) {
      long long int d = *(--p.upper_bound(pos[i] - i + 1));
      long long int temp = pos[i];
      swap(pos[i], pos[arr[temp - d + 1] - 1]);
      swap(arr[temp], arr[temp - d + 1]);
      out.push_back(make_pair(temp - d + 2, temp + 1));
    }
  }
  cout << out.size() << endl;
  for (auto x : out) cout << x.first << " " << x.second << endl;
  return 0;
}
