#include <bits/stdc++.h>
using namespace std;
bool marked[100000 + 2];
vector<int> prime;
int ase[100000 + 2], num[100000 + 2];
bool isPrime(int n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  return marked[n] == false;
}
void sieve(int n) {
  for (int i = 3; i * i <= n; i += 2) {
    if (marked[i] == false) {
      for (int j = i * i; j <= n; j += i + i) {
        marked[j] = true;
      }
    }
  }
  prime.push_back(2);
  for (int i = 3; i <= n; i += 2) {
    if (!marked[i]) {
      prime.push_back(i);
    }
  }
}
vector<pair<int, int> > ans;
void correct(int x) {
  if (num[x] == x) {
    return;
  }
  int j = ase[x];
  int k = j - *(upper_bound(prime.begin(), prime.end(), j - x + 1) - 1) + 1;
  int a;
  a = num[j], num[j] = num[k], num[k] = a;
  ase[num[k]] = k, ase[num[j]] = j;
  ans.push_back(pair<int, int>(k, j));
  correct(x);
}
int main(int argc, char** argv) {
  sieve(100000);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    ase[num[i]] = i;
  }
  getchar();
  for (int i = 1; i <= n; i++) {
    correct(i);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i].first << ' ' << ans[i].second << endl;
  }
  return 0;
}
