#include <bits/stdc++.h>
using namespace std;
void reverse_arr(int l, int r, char a[]) {
  while (l < r) {
    char t = a[l];
    a[l] = a[r];
    a[r] = t;
    l++;
    r--;
  }
}
int main() {
  int n, i;
  cin >> n;
  char a[n];
  cin >> a;
  for (i = 1; i <= n; i++) {
    if (n % i == 0) {
      reverse_arr(0, i - 1, a);
    }
  }
  cout << a << endl;
  return 0;
}
