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