#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, a[50], c = 0;
  string s;
  cin >> n;
  getchar();
  cin >> s;
  for (i = 2; i <= n; i++) {
    if (n % i == 0) {
      a[c] = i;
      c++;
    }
  }
  sort(a, a + c);
  for (i = 0; i < c; i++) {
    reverse(s.begin(), s.begin() + a[i]);
  }
  cout << s << endl;
}
