#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int t[100005], a[100005], n;
vector<pair<int, int> > ans;
int vis[100005], lst[100005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) {
      lst[i] = i;
      for (int j = i + i; j <= n; j += i) vis[j] = 1;
    } else
      lst[i] = lst[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    t[a[i]] = i;
  }
  int p, now;
  for (int i = 1; i <= n; i++) {
    while (t[i] != i) {
      p = lst[t[i] - i + 1];
      p = t[i] - p + 1;
      ans.emplace_back(make_pair(p, t[i]));
      swap(t[i], t[a[p]]);
      swap(a[t[i]], a[t[a[p]]]);
    }
  }
  cout << ans.size() << '\n';
  for (auto u : ans) {
    cout << u.first << ' ' << u.second << '\n';
  }
  return 0;
}
