#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int n, s, e;
  cin >> n;
  string str;
  cin >> str;
  for (int i = 0; i < str.length(); i++) {
    if (n % (i + 1) != 0) continue;
    s = 0;
    e = i;
    while (e > s) {
      char temp = str[e];
      str[e] = str[s];
      str[s] = temp;
      e--;
      s++;
    }
  }
  cout << str;
  return 0;
}
