#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i;
  char c;
  vector<char> in;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> c;
    in.push_back(c);
  }
  if (n == 1) {
    cout << in[0] << endl;
    return 0;
  }
  if (n == 2) {
    cout << in[1] << in[0] << endl;
    return 0;
  }
  vector<long long> arr;
  for (i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      arr.push_back(i);
      if (n / i != i) {
        arr.push_back(n / i);
      }
    }
  }
  arr.push_back(n);
  sort(arr.begin(), arr.end());
  for (i = 0; i < arr.size(); i++) {
    reverse(in.begin(), in.begin() + arr[i]);
  }
  for (i = 0; i < n; i++) {
    cout << in[i];
  }
  cout << endl;
  return 0;
}
