#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
int n, prime[100005], a[100005], pos[100005], t[100005];
int main() {
  prime[0] = prime[1] = 1;
  for (int i = 2; i * i <= 100000; i++)
    if (!prime[i])
      for (int j = i; j * i <= 100000; j++) prime[j * i] = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  int st = 0;
  for (int i = 2; i <= n; i++)
    if (!prime[i]) t[st++] = i;
  for (int i = 1; i <= n; i++) {
    int d = pos[i] - i + 1;
    while (d != 1) {
      int c;
      c = *(upper_bound(t, t + st, d) - 1);
      ans.push_back(make_pair(pos[i] - c + 1, pos[i]));
      int temp = pos[i];
      pos[i] = pos[i] - c + 1;
      pos[a[temp - c + 1]] = temp;
      swap(a[temp - c + 1], a[temp]);
      d = pos[i] - i + 1;
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
