#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> del;
  for (int i = 2; i <= n; i++) {
    if (n % i == 0) del.push_back(i);
  }
  string r = "";
  for (int i = 0; i < del.size(); i++) {
    for (int j = del[i] - 1; j >= 0; j--) {
      r += s[j];
    }
    for (int k = 0; k < r.size(); k++) {
      s[k] = r[k];
    }
    r = "";
  }
  cout << s << endl;
}
