#include <bits/stdc++.h>
void reverse(char str[], int start, int end) {
  if (start == end)
    return;
  else {
    int len = end - start + 1;
    for (int i = 0; i < len / 2; i++) {
      char temp = str[i];
      str[i] = str[len - i - 1];
      str[len - i - 1] = temp;
    }
  }
}
int main() {
  int n;
  scanf("%d\n", &n);
  char str[n + 1];
  scanf("%s", str);
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) reverse(str, 0, i - 1);
  }
  printf("%s", str);
}
