#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  char temp;
  for (int k = 1; k <= n; k++) {
    if (n % k == 0) {
      for (int i = 0; i < (k / 2); i++) {
        temp = s[i];
        s[i] = s[k - i - 1];
        s[k - i - 1] = temp;
      }
    }
  }
  cout << s << endl;
  return 0;
}
