#include <bits/stdc++.h>
using namespace std;
int n;
int ar[200000];
int pos[200000];
vector<pair<int, int> > ans;
vector<int> prime;
bool used[200000];
inline void primes() {
  for (int i = 2; i <= n; i++) {
    if (used[i]) continue;
    for (int j = 2 * i; j <= n; j += i) used[j] = true;
    prime.push_back(i);
  }
}
void sol(int num) {
  if (pos[num] == num) return;
  int i, j;
  j = pos[num];
  i = num;
  int prim = *(upper_bound(prime.begin(), prime.end(), j - i + 1) - 1);
  i = j - prim + 1;
  swap(ar[i], ar[j]);
  pos[ar[i]] = i;
  pos[ar[j]] = j;
  ans.push_back(make_pair(i, j));
  sol(num);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", ar + i);
    pos[ar[i]] = i;
  }
  primes();
  for (int i = 1; i <= n; i++) sol(i);
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
}
