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