#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
void solve() {
  long long int n;
  cin >> n;
  long long int a[n + 1];
  map<long long int, long long int> y;
  for (long long int i = 1; i <= n; i++) cin >> a[i], y[a[i]] = i;
  vector<pair<long long int, long long int>> ans;
  long long int is_prime[N];
  for (int i = 2; i < N; i++) is_prime[i] = 1;
  is_prime[1] = 0;
  for (long long int i = 2; i < N; i++) {
    if (is_prime[i] == 1) {
      for (long long int j = i * i; j < N; j += i) is_prime[j] = 0;
    }
  }
  long long int pre;
  for (int i = 2; i < N; i++) {
    if (is_prime[i]) pre = i;
    is_prime[i] = pre;
  }
  for (long long int i = 1; i <= n; i++) {
    while (a[i] != i) {
      long long int crt_pos = y[i];
      long long int dif = crt_pos - i + 1;
      long long int can = is_prime[dif];
      can--;
      ans.push_back({crt_pos - can, crt_pos});
      swap(a[crt_pos - can], a[crt_pos]);
      y[a[crt_pos]] = crt_pos;
      y[a[crt_pos - can]] = crt_pos - can;
    }
  }
  cout << ans.size() << "\n";
  for (auto X : ans) cout << X.first << " " << X.second << "\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
}
